- constructor(options)
- account
- bitIndexer
- bitBuilder
- signer
- status
- subAccounts(params)
- checkSubAccounts(subAccounts)
- mintSubAccounts(params)
- mintSubAccount(params)
- changeOwner(keyInfo)
- changeManager(keyInfo)
- updateRecords(records)
- editRecords()
- info()
- owner()
- manager()
- records(key)
- addresses(chain)
- addrs(chain)
- dwebs(protocol)
- dweb()
- profiles(subtype)
- avatar(account)
To create a BitAccount instance.
- options:
BitAccountOptions
- account:
string
, - (Optional) bitIndexer:
BitIndexer
, - (Optional) bitBuilder:
RemoteTxBuilder
, - (Optional) signer:
BitSigner
,
- account:
BitAccount
const { createInstance } = require('dotbit')
const dotbit = createInstance()
// To create a BitAccount instance.
const account = dotbit.account('west.bit')
console.log(account);
// ...
// The printed result would be like:
BitAccount {
account: 'west.bit'
}
To get the account of a BitAccount instance.
N/A
string
const { createInstance } = require('dotbit')
// create dotbit instance
const dotbit = createInstance()
// To create a BitAccount instance.
const account = dotbit.account('west.bit')
console.log(account.account);
// ...
// The printed result would be like:
west.bit
To get the indexer of current BitAccount instance.
N/A
BitIndexer
const { createInstance } = require('dotbit')
// create dotbit instance
const dotbit = createInstance()
// To create a BitAccount instance.
const account = dotbit.account('west.bit')
// To get the indexer of current BitAccount instance
console.log(account.bitIndexer)
// ...
// The printed result would be like:
BitIndexer { }
To get the builder of current BitAccount instance.
N/A
RemoteTxBuilder
const { createInstance } = require('dotbit')
// create dotbit instance
const dotbit = createInstance()
// To create a BitAccount instance.
const account = dotbit.account('west.bit')
// To get the builder of current BitAccount instance
console.log(account.bitBuilder)
// ...
// The printed result would be like:
RemoteTxBuilder {
}
To get the signer of current BitAccount instance.
N/A
BitSigner
const { Wallet, QuickNodeProvider } = require('ethers')
const { createInstance, EvmSigner } = require('dotbit')
const privateKey = "INPUT_YOUR_PRIVATE_KEY_HERE";
const provider = new QuickNodeProvider()
const wallet = new Wallet(privateKey, provider)
const signer = new EvmSigner(wallet)
const dotbit = createInstance({
signer: signer
})
const account = dotbit.account('west.bit')
// To get the signer of current BitAccount instance
console.log(account.signer)
To get the account status of current BitAccount instance.
To get the full status of a .bit account, check out here: Account Status Enum
N/A
AccountStatus
const { createInstance } = require('dotbit')
// create dotbit instance
const dotbit = createInstance()
// To create a BitAccount instance.
const account = dotbit.account('west.bit')
// To get the account status of 'west.bit'
console.log(account.status)
// ...
// The printed result would be like:
6 // AccountStatus
List the sub accounts of a main account, with pagination and filter.
- (Optional) params:
Omit<SubAccountListParams, 'account'>
- page:
number
. The default value is1
. - size:
number
. The default value is100
. - keyword:
string
. The default value is''
.
- page:
Promise<SubAccountListRes
>
const { createInstance } = require('dotbit')
const dotbit = createInstance()
const account = dotbit.account('west.bit')
// To list the sub-accounts of a main account, with 100 items per page.
const subAccounts = await account.subAccounts()
console.log(subAccounts)
// ...
// The printed result would be like:
{ total: 100, list: [
...,
{
account: 'xxy229.makeafriend.bit',
owner: [Object],
manager: [Object],
registered_at: 1669713664000,
expired_at: 1701249664000,
status: 0,
enable_sub_account: 0,
renew_sub_account_price: 0,
nonce: 0
},
...,
]}
To check if all given sub-accounts could be registered.
- subAccounts:
SubAccountMintParams
Promise<{result: SubAccountWithStatus[]
}>
const { createInstance } = require('dotbit')
const dotbit = createInstance()
const account = dotbit.account('west.bit')
const subAccounts: SubAccountMintParams[] = [{
account: 'xyz.imac.bit',
type: 'blockchain',
key_info: {
key: '0x7df93d9F500fD5A9537FEE086322a988D4fDCC38',
coin_type: 'eth',
},
register_years: 1,
account_char_str: graphemesAccount('xyz')
}]
const result = await account.checkSubAccounts(subAccounts)
// ...
// The printed result would be like:
{
result: [
{
account: 'xyz.imac.bit',
mint_for_account: '',
account_char_str: [Array],
register_years: 1,
type: 'blockchain',
key_info: [Object],
status: 1,
message: 'account suffix diff: imac.bit'
}
]
}
To mint multiple sub-accounts for a BitAccount instance.
Note: This is a write API, which means you need to set up a signer before calling it. See example below for how to set up a signer. Note: Currently, Second-level DID is fully available in testnet, and need whitelist on mainnet. If you would like to distribute Second-level DIDs on mainnet, please email [email protected] with a brief description of your project.
- params:
SubAccountParams[]
- account:
string
, - (Optional) keyInfo:
KeyInfo
. (The keyInfo has a higher priority than mintForAccount.) - (Optional) mintForAccount:
string
, - registerYears:
number
,
- account:
Promise<{ hash?: string
, hash_list: string[]
}>
const { Wallet, QuickNodeProvider } = require('ethers')
const { createInstance, EvmSigner } = require('dotbit')
const privateKey = "INPUT_YOUR_PRIVATE_KEY_HERE";
const provider = new QuickNodeProvider()
const wallet = new Wallet(privateKey, provider)
const signer = new EvmSigner(wallet)
const dotbit = createInstance({
signer: signer
})
const account = dotbit.account('imac.bit')
const mintParam = [{
account: '006.imac.bit',
keyInfo: {
coin_type: 'eth',
key: '0x7df93d9F500fD5A9537FEE086322a988D4fDCC38',
},
registerYears: 1,
}, {
account: '007.imac.bit',
keyInfo: {
coin_type: 'eth',
key: '0x7df93d9F500fD5A9537FEE086322a988D4fDCC38',
},
registerYears: 1,
}, {
account: '008.imac.bit',
registerYears: 1,
mintForAccount: 'imac.bit'
}]
const result = await account.mintSubAccounts(mintParam);
console.log(result);
// ...
// The printed result would be like:
{
hash: '0xadc19c5a8bd9ce963cbfc876e55a9f11b0518073114ceb967d521e695d8b41a4'
}
To mint a sub-account for a BitAccount instance.
Note: This is a write API, which means you need to set up a signer before calling it. See example below for how to set up a signer. Note: Currently, Second-level DID is fully available in testnet, and need whitelist on mainnet. If you would like to distribute Second-level DIDs on mainnet, please email [email protected] with a brief description of your project.
- params:
SubAccountParams
- account:
string
, - (Optional) keyInfo:
KeyInfo
. (The keyInfo has a higher priority than mintForAccount.) - (Optional) mintForAccount:
string
, - registerYears:
number
,
- account:
Promise<{ hash?: string
, hash_list: string[]
}>
const { Wallet, QuickNodeProvider } = require('ethers')
const { createInstance, EvmSigner } = require('dotbit')
const privateKey = "INPUT_YOUR_PRIVATE_KEY_HERE";
const provider = new QuickNodeProvider()
const wallet = new Wallet(privateKey, provider)
const signer = new EvmSigner(wallet)
const dotbit = createInstance({
signer: signer
})
const account = dotbit.account('imac.bit')
const mintParam = {
account: '005.imac.bit',
keyInfo: {
coin_type: 'eth',
key: '0x7df93d9F500fD5A9537FEE086322a988D4fDCC38',
},
registerYears: 1,
}
const result = await account.mintSubAccount(mintParam);
console.log(result);
// ...
// The printed result would be like:
{
hash: '0xadc19c5a8bd9ce963cbfc876e55a9f11b0518073114ceb967d521e695d8b41a4'
}
To change the owner of a BitAccount instance.
Note: This is a write API, which means you need to set up a signer before calling it. See example below for how to set up a signer.
- keyInfo:
KeyInfo
- key:
string
. The address on a certain blockchain - (Optional) 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<{ hash?: string
, hash_list: string[]
}>
const { Wallet, QuickNodeProvider } = require('ethers')
const { createInstance, EvmSigner } = require('dotbit')
const privateKey = "INPUT_YOUR_PRIVATE_KEY_HERE";
const provider = new QuickNodeProvider()
const wallet = new Wallet(privateKey, provider)
const signer = new EvmSigner(wallet)
const dotbit = createInstance({
signer: signer
})
const account = dotbit.account('west.bit')
const result = await account.changeOwner({
key: '0x1d643fac9a463c9d544506006a6348c234da485f',
coin_type: "60" // The coin type of ETH
})
console.log(result);
// ...
// The printed result would be like:
{
hash: '0xadc19c5a8bd9ce963cbfc876e55a9f11b0518073114ceb967d521e695d8b41a4'
}
To change the manager of a BitAccount instance.
Note: This is a write API, which means you need to set up a signer before calling it. See example below for how to set up a signer.
- keyInfo:
KeyInfo
- key:
string
. The address on a certain blockchain - (Optional) 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<{ hash?: string
, hash_list: string[]
}>
const { Wallet, QuickNodeProvider } = require('ethers')
const { createInstance, EvmSigner } = require('dotbit')
const privateKey = "INPUT_YOUR_PRIVATE_KEY_HERE";
const provider = new QuickNodeProvider()
const wallet = new Wallet(privateKey, provider)
const signer = new EvmSigner(wallet)
const dotbit = createInstance({
signer: signer
})
const account = dotbit.account('west.bit')
const result = await account.changeManager({
key: '0x1d643fac9a463c9d544506006a6348c234da485f',
coin_type: "60" // The coin type of ETH
})
console.log(result);
// ...
// The printed result would be like:
{
hash: '0xadc19c5a8bd9ce963cbfc876e55a9f11b0518073114ceb967d521e695d8b41a4'
}
To update all records of a BitAccount instance.
Note: This is a write API, which means you need to set up a signer before calling it. See example below for how to set up a signer. Note: The existing records will be erased.
- records:
BitAccountRecord[]
- key:
string
, - value:
string
, - label:
string
, - ttl:
string
,
- key:
Promise<{ hash?: string
, hash_list: string[]
}>
const { Wallet, QuickNodeProvider } = require('ethers')
const { createInstance, EvmSigner } = require('dotbit')
const privateKey = "INPUT_YOUR_PRIVATE_KEY_HERE";
const provider = new QuickNodeProvider()
const wallet = new Wallet(privateKey, provider)
const signer = new EvmSigner(wallet)
const dotbit = createInstance({
signer: signer
})
const account = dotbit.account('west.bit')
const result = await account.updateRecords([{
key: 'profile.email',
value: '[email protected]',
label: 'HR',
ttl: '3000',
}])
console.log(result);
// ...
// The printed result would be like:
{
hash: '0xadc19c5a8bd9ce963cbfc876e55a9f11b0518073114ceb967d521e695d8b41a4'
}
To create a record editor for a BitAccount instance.
Note: This is a write API, which means you need to set up a signer before calling it. See example below for how to set up a signer.
N/A
RecordsEditor
const { Wallet, QuickNodeProvider } = require('ethers')
const { createInstance, EvmSigner } = require('dotbit')
const privateKey = "INPUT_YOUR_PRIVATE_KEY_HERE";
const provider = new QuickNodeProvider()
const wallet = new Wallet(privateKey, provider)
const signer = new EvmSigner(wallet)
const dotbit = createInstance({
signer: signer,
})
const account = dotbit.account('imac.bit')
const editor = await account.editRecords()
editor.delete({
key: 'profile.email',
}).add({
key: 'profile.email',
value: '[email protected]',
})
console.log(editor.records)
// ...
// The printed result would be like:
[
{
ttl: '300',
label: '',
key: 'profile.email',
value: '[email protected]'
}
]
To get the account info of a BitAccount instance.
N/A
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
,
const { createInstance } = require('dotbit')
const dotbit = createInstance()
const account = dotbit.account('imac.bit')
// Get the account info of "imac.bit"
account.info().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
}
To get the owner of a BitAccount instance.
N/A
Promise<RoleKeyInfo
>
- key:
string
. The address on a certain blockchain - (Optional) 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. - algorithm_id:
number
const { createInstance } = require('dotbit')
const dotbit = createInstance()
const account = dotbit.account('west.bit')
// Get the owner of "west.bit"
account.owner().then(console.log)
// ...
// The printed result would be like:
{
key: '0xb2be2887a26f44555835eeacc47d65b88b6b42c2',
coin_type: '60',
algorithm_id: 17000
}
To get the manager of a BitAccount instance.
N/A
Promise<RoleKeyInfo
>
- key:
string
. The address on a certain blockchain - (Optional) 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. - algorithm_id:
number
const { createInstance } = require('dotbit')
const dotbit = createInstance()
const account = dotbit.account('west.bit')
// Get the manager of "west.bit"
account.manager().then(console.log)
// ...
// The printed result would be like:
{
key: '0xb2be2887a26f44555835eeacc47d65b88b6b42c2',
coin_type: '60',
algorithm_id: 17000
}
To get all records of a BitAccount instance.
- (Optional) 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
,
const { createInstance } = require('dotbit')
const dotbit = createInstance()
const account = dotbit.account('west.bit')
// Get all records of "west.bit"
account.records().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"
account.records("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.
- (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
,
const { createInstance } = require('dotbit')
const dotbit = createInstance()
const account = dotbit.account('west.bit')
// Get all addresses of "west.bit"
account.addresses().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
account.addresses("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.
account.addresses("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(chain).
Get all DWebs of a BitAccount instance
- (Optional) protocol:
string
. Only records of matched subtype will be displayed.
Promise<BitAccountRecordExtended[]>
- key:
string
, - value:
string
, - label:
string
, - ttl:
string
, - type:
string
, - subtype:
string
,
const { createInstance } = require('dotbit')
const dotbit = createInstance()
const account = dotbit.account('code.bit')
// Get all DWebs of "code.bit"
account.dwebs().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"
account.dwebs("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 BitAccount instance. If multiple DWebs are owned by an account, the result will be displayed in this order of priority: 'ipns', 'ipfs', 'skynet', 'resilio'.
N/A
Promise<BitAccountRecordExtended>
- key:
string
, - value:
string
, - label:
string
, - ttl:
string
, - type:
string
, - subtype:
string
,
const { createInstance } = require('dotbit')
const dotbit = createInstance()
const account = dotbit.account('code.bit')
// Get the first DWeb of "code.bit"
account.dweb().then(console.log)
// ...
// The printed result would be like:
{
key: 'dweb.ipns',
label: '',
value: 'k51qzi5uqu5dgqjy1i78mz3oumplzt0cye32w9m8ix8hg9chpz5trvj8luwv0c',
ttl: '300',
type: 'dweb',
subtype: 'ipns'
}
To get all profiles of a BitAccount instance.
- (Optional) subtype:
string
Promise<BitAccountRecordExtended[]
>
- key:
string
, - value:
string
, - label:
string
, - ttl:
string
, - type:
string
, - subtype:
string
,
const { createInstance } = require('dotbit')
const dotbit = createInstance()
const account = dotbit.account('west.bit')
// Get all profiles of "west.bit"
account.profiles().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"
account.profiles("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