- constructor(config)
- network
- cacheProvider
- bitIndexer
- bitBuilder
- signer
- plugins
- installPlugin(plugin)
- uninstallPlugin(plugin)
- serverInfo()
- reverse(keyInfo)
- alias
- accountsOfOwner(keyInfo)
- accountsOfManager(keyInfo)
- account(account)
- exist(account)
- accountById(accountId)
- records(account, key)
- accountInfo(account)
- addresses(account, chain)
- addrs(account, chain)
- dwebs(account, key)
- dweb(account)
- profiles(account, key)
- avatar(account)
- verifyAddrsByAccount(address, account, subAccount, verifyType)
- validDotbitAliasAddresses(account)
- batchAccountInfo(accounts)
- dobList(keyInfo, didType, page, size)
To create a new DotBit instance.
Note: For a better development experience, we suggest you using
createInstance
to initialize DotBit, since it has already set a bunch of default configs (e.g. network, indexer, builder and signer).
config: DotBitConfig
- (Optional) network:
BitNetwork
, - (Optional) cacheProvider:
CacheProvider
, - (Optional) bitIndexer:
BitIndexer
, - (Optional) bitBuilder:
RemoteTxBuilder
, - (Optional) signer:
BitSigner
,
DotBit
const { DotBit } = require('dotbit');
// To create a new DotBit instance.
const config = {
network: "testnet",
bitIndexer: new BitIndexer({
uri: "https://test-indexer.d.id",
}),
bitBuilder: new RemoteTxBuilder({
subAccountUri: "https://test-subaccount-api.d.id/v1",
registerUri: "https://test-register-api.d.id/v1",
}),
};
const dotbit = new DotBit(config);
console.log(dotbit);
// ...
// The printed result would be like:
DotBit {
plugins: [],
network: 'testnet',
bitIndexer: BitIndexer {},
bitBuilder: RemoteTxBuilder {},
}
To get the network of current DotBit instance.
N/A
'mainnet' | 'testnet'
// To get the network of current DotBit instance.
console.log(dotbit.network)
// ...
// The printed result would be like:
mainnet
To get the cache provider of current DotBit instance.
N/A
CacheProvider
// To get the cache provider of current DotBit instance
console.log(dotbit.cacheProvider)
// ...
// The printed result would be like:
{ get: [Function: get], set: [Function: set] }
To get the indexer of current DotBit instance.
N/A
BitIndexer
// To get the indexer of current DotBit instance
console.log(dotbit.bitIndexer)
// ...
// The printed result would be like:
BitIndexer { rpc: JSONRPC { url: 'https://indexer-v1.d.id', id: 0 } }
To get the builder of current DotBit instance.
N/A
RemoteTxBuilder
// To get the builder of current DotBit instance.
console.log(dotbit.bitBuilder)
// ...
// The printed result would be like:
RemoteTxBuilder {
subAccountAPI: SubAccountAPI {
baseUri: 'https://subaccount-api.d.id/v1',
net: Networking { baseUri: 'https://subaccount-api.d.id/v1' }
},
registerAPI: RegisterAPI {
baseUri: 'https://register-api.d.id/v1',
net: Networking { baseUri: 'https://register-api.d.id/v1' }
}
}
To get the signer of current DotBit instance.
N/A
BitSigner
// To get the signer of current DotBit instance.
console.log(dotbit.signer)
To get all the installed plugins in current DotBit instance.
N/A
BitPluginBase[]
- (Optional) version:
string
, - (Optional) name:
string
, - onInstall:
(dotbit: DotBit) => void
, - (Optional) onUninstall:
(dotbit: DotBit) => void
, - (Optional) onInitAccount:
(bitAccount: BitAccount) => void
,
// To get all the installed plugins in current DotBit instance
console.log(dotbit.plugins)
// ...
// The printed result would be like:
undefined
To install a plugin for .bit SDK.
- plugin: BitPluginBase
- (Optional) version:
string
, - (Optional) name:
string
, - onInstall:
(dotbit: DotBit) => void
, - (Optional) onUninstall:
(dotbit: DotBit) => void
, - (Optional) onInitAccount:
(bitAccount: BitAccount) => void
,
- (Optional) version:
N/A
import { createInstance } from 'dotbit'
import { BitPluginAvatar } from '@dotbit/plugin-avatar'
const dotbit = createInstance()
// To install the BitPluginAvatar plugin
dotbit.installPlugin(new BitPluginAvatar())
dotbit.avatar('imac.bit').then(console.log) // { url: 'https://thiscatdoesnotexist.com' }
To uninstall a plugin for .bit SDK.
- plugin: BitPluginBase
- (Optional) version:
string
, - (Optional) name:
string
, - onInstall:
(dotbit: DotBit) => void
, - (Optional) onUninstall:
(dotbit: DotBit) => void
, - (Optional) onInitAccount:
(bitAccount: BitAccount) => void
,
- (Optional) version:
N/A
import { createInstance } from 'dotbit'
import { BitPluginAvatar } from '@dotbit/plugin-avatar'
const dotbit = createInstance()
const avatarPlugin = new BitPluginAvatar()
dotbit.installPlugin(avatarPlugin)
// ...
// To uninstall the BitPluginAvatar plugin
dotbit.uninstallPlugin(avatarPlugin)
To get the server info of current .bit indexer.
N/A
Promise
- is_latest_block_number:
boolean
, - current_block_number:
number
,
// To get the server info of current .bit indexer
dotbit.serverInfo().then(console.log);
// ...
// The printed result would be like:
{ is_latest_block_number: true, current_block_number: 8834119 }
To get the .bit alias for a given blockchain address
Note: Only when .bit alias is set at https://d.id/bit/alias by user, reverse record is valid.
- keyInfo:
KeyInfo
- key:
string
. The address on a certain blockchain - coin_type:
string
. (60: ETH, 195: TRX, 9006: BNB, 966: Matic, 3: Doge, 309: CKB). See What is coin_type? in FAQ for more details.
- key:
Promise
// To get the BitAccount instance of Ethereum addresss '0x1d643fac9a463c9d544506006a6348c234da485f'
dotbit.reverse({
key: '0x1d643fac9a463c9d544506006a6348c234da485f',
coin_type: "60" // The coin type of ETH
}).then(console.log)
// ...
// The printed result would be like:
BitAccount {
account: 'jeffx.bit',
bitIndexer: BitIndexer {},
bitBuilder: RemoteTxBuilder {},
signer: // Your signer instance
}
The API is the same as reverse(keyInfo).
List all .bit accounts (including Second-level DID accounts) of a given blockchain owner address
- keyInfo:
KeyInfo
- key:
string
. The address on a certain blockchain - coin_type:
string
. (60: ETH, 195: TRX, 9006: BNB, 966: Matic, 3: Doge, 309: CKB). See What is coin_type? in FAQ for more details.
- key:
Promise<BitAccountListItem[]>
// To get all BitAccount instances of Ethereum addresss '0x1d643fac9a463c9d544506006a6348c234da485f'
dotbit.accountsOfOwner({
key: "0x1d643fac9a463c9d544506006a6348c234da485f",
coin_type: "60" // The coin type of ETH
}).then(console.log);
// ...
// The printed result would be like:
[
...,
{
"account": "gaoyuanyuan.bit",
"display_name": "gaoyuanyuan.bit",
"registered_at": 1626962335,
"expired_at": 1721570335
}
]
List all .bit accounts (including Second-level DID accounts) of a given blockchain manager address
- keyInfo:
KeyInfo
- key:
string
. The address on a certain blockchain - coin_type:
string
. (60: ETH, 195: TRX, 9006: BNB, 966: Matic, 3: Doge, 309: CKB). See What is coin_type? in FAQ for more details.
- key:
Promise<BitAccountListItem[]>
// To get all BitAccount instances of Ethereum addresss '0x1d643fac9a463c9d544506006a6348c234da485f'
dotbit.accountsOfManager({
key: "0x1d643fac9a463c9d544506006a6348c234da485f",
coin_type: "60" // The coin type of ETH
}).then(console.log);
// ...
// The printed result would be like:
[
...,
{
"account": "gaoyuanyuan.bit",
"display_name": "gaoyuanyuan.bit",
"registered_at": 1626962335,
"expired_at": 1721570335
}
]
To get the BitAccount instance of a given account name.
- account:
string
BitAccount (Note: It is not a promise.)
// To get the BitAccount instance of "west.bit"
const result = dotbit.account("west.bit");
console.log(result);
// ...
// The printed result would be like:
BitAccount {
account: 'west.bit',
bitIndexer: BitIndexer {},
bitBuilder: RemoteTxBuilder {},
signer: // Your signer instance
}
To determine whether a given account exists.
- account:
string
Promise<boolean>
// To check if the account "west.bit" exists
dotbit.exist("west.bit").then(console.log)
// ...
// The printed result would be like:
true
To get the BitAccount instance of a given account ID.
- accountId:
string
. Remember it is a hexadecimal ID, not the account name.
Promise<BitAccount>
// To get the BitAccount instance of account ID '0x5728088435fb8788472a9ca601fbc0b9cbea8be3'
dotbit.accountById("0x5728088435fb8788472a9ca601fbc0b9cbea8be3").then(console.log);
// ...
// The printed result would be like:
BitAccount {
account: 'imac.bit',
bitIndexer: BitIndexer {},
bitBuilder: RemoteTxBuilder {},
signer: // Your signer instance
}
To get all records of a given account.
- account:
string
- key:
string
. The key related to a specific record, only the matched record will be displayed.
Promise<BitAccountRecordExtended[]>
- key:
string
, - value:
string
, - label:
string
, - ttl:
string
, - type:
string
, - subtype:
string
,
// Get all records of "west.bit"
dotbit.records("west.bit").then(console.log)
// ...
// The printed result would be like:
[
...
{
key: 'address.polygon',
label: 'Usually',
value: '0xB2bE2887A26f44555835EEaCC47d65B88b6B42c2',
ttl: '300',
type: 'address',
subtype: 'polygon'
},
{
key: 'profile.discord',
label: 'Discord Username',
value: 'west.bit#8906',
ttl: '300',
type: 'profile',
subtype: 'discord'
},
...
]
// Get record of profile.discord of "west.bit"
dotbit.records("west.bit", "profile.discord").then(console.log)
// ...
// The printed result would be like:
[
{
key: 'profile.discord',
label: 'Discord Username',
value: 'west.bit#8906',
ttl: '300',
type: 'profile',
subtype: 'discord'
}
]
Note: If no record with the given key exists, an empty array will be returned.
To get the account info of a given account.
- account:
string
Promise<AccountInfo>
- account:
string
, - account_id_hex:
string
, - next_account_id_hex:
string
, - create_at_unix:
number
, - expired_at_unix:
number
, - status:
number
, - das_lock_arg_hex:
string
, - owner_algorithm_id:
number
, - owner_key:
string
, - manager_algorithm_id:
number
, - manager_key:
string
, - enable_sub_account:
number
,
// Get the account info of "imac.bit"
dotbit.accountInfo("imac.bit").then(console.log)
// ...
// The printed result would be like:
{
account: 'imac.bit',
account_id_hex: '0x5728088435fb8788472a9ca601fbc0b9cbea8be3',
next_account_id_hex: '0x57280ab92f213d74c7a185e9b9d26d0a795108de',
create_at_unix: 1671164348,
expired_at_unix: 1702700348,
status: 0,
das_lock_arg_hex: '0x05b2be2887a26f44555835eeacc47d65b88b6b42c205b2be2887a26f44555835eeacc47d65b88b6b42c2',
owner_algorithm_id: 17000,
owner_key: '0xb2be2887a26f44555835eeacc47d65b88b6b42c2',
manager_algorithm_id: 17000,
manager_key: '0xb2be2887a26f44555835eeacc47d65b88b6b42c2',
enable_sub_account: 0
}
- account:
string
- (Optional) chain:
string
. It could be the coin types defined in slip44(e.g. '60' for ETH / '9006' for BSC). It could also be the symbols of coin (e.g. 'eth' / 'bsc')
Promise<BitAccountRecordAddress[]>
- key:
string
, - value:
string
, - label:
string
, - ttl:
string
, - type:
string
, - subtype:
string
, - coin_type:
string
,
// Get all addresses of "west.bit"
dotbit.addresses("west.bit").then(console.log)
// ...
// The printed result would be like:
[
{
key: 'address.bsc',
label: 'HyperPay',
value: '0x44A042eFA495A10E10d47269BB33bcB4991b80f4',
ttl: '300',
type: 'address',
subtype: 'bsc',
coin_type: '9006'
},
{
key: 'address.trx',
label: 'HyperPay',
value: 'TJBr5JqG8mUX6PdKAbM4Qy3n1eZe7wP8bv',
ttl: '300',
type: 'address',
subtype: 'trx',
coin_type: '195'
},
...
]
// Get the Ethereum address of "west.bit" by passing coin types
dotbit.addresses("west.bit", "60").then(console.log);
// Get the Ethereum address of "west.bit" by passing coin symbols
// Note: Developers are encouraged to use coin_type instead of plain symbol like 'eth' as coin_type is a more standard way to identify a chain/coin, and there will only be coin_type on chain in the future.
dotbit.addresses("west.bit", "eth").then(console.log);
// ...
// The printed result would be the same:
[
{
key: 'address.eth',
label: 'Private Account',
value: '0xB2bE2887A26f44555835EEaCC47d65B88b6B42c2',
ttl: '300',
type: 'address',
subtype: 'eth',
coin_type: '60'
}
]
An alias for API addresses(account, chain).
Get all DWebs of a given account
- account:
string
- key:
string
. Only records of matched subtype will be displayed.
Promise<BitAccountRecordExtended[]>
- key:
string
, - value:
string
, - label:
string
, - ttl:
string
, - type:
string
, - subtype:
string
,
// Get all DWebs of "code.bit"
dotbit.dwebs("code.bit").then(console.log)
// ...
// The printed result would be like:
[
{
key: 'dweb.ipns',
label: '',
value: 'k51qzi5uqu5dgqjy1i78mz3oumplzt0cye32w9m8ix8hg9chpz5trvj8luwv0c',
ttl: '300',
type: 'dweb',
subtype: 'ipns'
}
]
// Get all ipns DWebs of "code.bit"
dotbit.dwebs("code.bit", "ipns").then(console.log);
// ...
// The printed result would be like:
[
{
key: 'dweb.ipns',
label: '',
value: 'k51qzi5uqu5dgqjy1i78mz3oumplzt0cye32w9m8ix8hg9chpz5trvj8luwv0c',
ttl: '300',
type: 'dweb',
subtype: 'ipns'
}
]
Note: If no record with the given key exists, an empty array will be returned.
Get the first DWeb of a given account. If multiple DWebs are owned by an account, the result will be displayed in this order of priority: 'ipns', 'ipfs', 'skynet', 'resilio'.
- account:
string
Promise<BitAccountRecordExtended>
- key:
string
, - value:
string
, - label:
string
, - ttl:
string
, - type:
string
, - subtype:
string
,
// Get the first DWeb of "code.bit"
dotbit.dweb("code.bit").then(console.log)
// ...
// The printed result would be like:
{
key: 'dweb.ipns',
label: '',
value: 'k51qzi5uqu5dgqjy1i78mz3oumplzt0cye32w9m8ix8hg9chpz5trvj8luwv0c',
ttl: '300',
type: 'dweb',
subtype: 'ipns'
}
// Get the first DWeb of "west.bit"
dotbit.dweb("west.bit").then(console.log)
// ...
// The printed result would be null since no DWeb exists for "west.bit"
null
Get all profiles of a given account.
- account:
string
- key:
string
. Only profiles of matched subtype will be displayed.
Promise<BitAccountRecordExtended[]
>
- key:
string
, - value:
string
, - label:
string
, - ttl:
string
, - type:
string
, - subtype:
string
,
// Get all profiles of "west.bit"
dotbit.profiles("west.bit").then(console.log);
// ...
// The printed result would be like:
[
{
key: 'profile.discord',
label: 'Discord Username',
value: 'west.bit#8906',
ttl: '300',
type: 'profile',
subtype: 'discord'
},
{
key: 'profile.twitter',
label: '',
value: 'kylexiang',
ttl: '300',
type: 'profile',
subtype: 'twitter'
},
...
]
// Get Discord profile of "west.bit"
dotbit.profiles("west.bit", "discord").then(console.log);
// ...
// The printed result would be like:
[
{
key: 'profile.discord',
label: 'Discord Username',
value: 'west.bit#8906',
ttl: '300',
type: 'profile',
subtype: 'discord'
}
]
Get the avatar of a given account.
Note: You have to install @dotbit/plugin-avatar before using this API. Otherwise an error will be thrown.
- account:
string
For details, please refer to the documentation of @dotbit/plugin-avatar
Verify whether the provided address has associated Second-level DIDs within the given main account, serving as a gateway for community member participation.
- address:
string
Address to be verified. - mainAccount:
string
Specified .bit account. - (Optional)subAccount:
string
Specified Second-level DID.subAccount
is an optional field. If subAccount is empty, it will default to checking if the given address has at least one Second-level DID under any specified account. - (Optional)verifyType:
number
TheverifyType
is an optional field with a default value of 0, where 0 represents that theaddress
is the owner address of the Second-level DID, and 1 represents that theaddress
is the manager address of the Second-level DID.
Promise<boolean
>
// Check if the owner address has the Second-level DID 'leon.leonx.bit' under the main account 'leonx.bit'.
dotbit.verifyAddrsByAccount(
'0xC72B6f66017246d6A7f159F5C2BF358188AD9ECa',
'leonx.bit',
'leon.leonx.bit',
)
// The printed result would be like:
true
// Check if the manager address has any Second-level DID under the main account 'leonx.bit'.
dotbit.verifyAddrsByAccount(
'0xC72B6f66017246d6A7f159F5C2BF358188AD9ECa',
'leonx.bit',
null,
1
)
// The printed result would be like:
true
Query the valid alias address using the .bit alias.
- account:
string
. a .bit alias.
Promise<BitKeyInfo[]
>
dotbit.validDotbitAliasAddresses('imac.bit').then(console.log)
// The printed result would be like:
[
{
"type":"blockchain",
"key_info":{
"coin_type":"60",
"key":"0x15a33588908cf8edb27d1abe3852bf287abd3891"
}
}
]
Batch query of account information. Currently, only information about whether the account can be registered is returned. A maximum of 50 accounts can be queried at a time.
- accounts:
string[]
. List of accounts to be queried.
Promise<BatchAccountInfo[]
>
dotbit.batchAccountInfo(['imac.bit', 'imac-1.bit']).then(console.log)
// The printed result would be like:
[
{
"account": "imac.bit",
"can_register": false
},
{
"account": "imac-1.bit",
"can_register": true
},
...
]
Get .bit DOB list
- keyInfo:
KeyInfo
- key:
string
. The address on a certain blockchain - coin_type:
string
. (60: ETH, 195: TRX, 9006: BNB, 966: Matic, 3: Doge, 309: CKB). See What is coin_type? in FAQ for more details.
- key:
- (Optional) did_type:
number
. The default value is1
. 0 - all DOB, 1 - normal DOB, 2 - recyclable DOB. - (Optional) page:
number
. The default value is1
. - (Optional) size:
number
. The default value is100
.
Promise<DobInfo[]
>
dotbit.dobList({
key: 'ckt1qrejnmlar3r452tcg57gvq8patctcgy8acync0hxfnyka35ywafvkqgjqgygrcl4k7pjuafdzmlzwy8ws4dxja7uqqmuv8c5',
coin_type: '309'
}).then(console.log)
// The printed result would be like:
[
{
outpoint: '0xf2bc63cc3ea35c472c2625bd31f7c3cd309a3a493e179d6967f8314e231b5754-1',
account_id: '0x4f2308abb673d83fbdf4750e34ca84614de07957',
account: 'testckb.bit',
expired_at: 1725765831
},
...
]