To create a BitSubAccount instance.
- options:
BitAccountOptions
- account:
string
, - (Optional) bitIndexer:
BitIndexer
, - (Optional) bitBuilder:
RemoteTxBuilder
, - (Optional) signer:
BitSigner
,
- account:
BitSubAccount
const { BitSubAccount } = require('dotbit')
// To create a BitSubAccount instance.
const subAccount = new BitSubAccount({account: 'jeff.makeafriend.bit'});
console.log(subAccount);
// ...
// The printed result would be like:
BitSubAccount {
account: 'jeff.makeafriend.bit',
bitIndexer: undefined,
bitBuilder: undefined,
signer: undefined,
isSubAccount: true,
mainAccount: 'makeafriend.bit'
}
To get the main account of a Second-level DID.
N/A
string
const subAccount = new BitSubAccount({account: 'jeff.makeafriend.bit'});
// To get the main account of 'jeff.makeafriend.bit'.
console.log(subAccount.mainAccount);
// ...
// The printed result would be like:
makeafriend.bit
To change the owner of a Second-level DID.
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 { 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 subAccount = new BitSubAccount({account: 'jeff.makeafriend.bit', signer});
const result = await subAccount.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 Second-level DID.
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 { EvmSigner } = require('dotbit')
const { Wallet, QuickNodeProvider } = require('ethers')
const privateKey = "INPUT_YOUR_PRIVATE_KEY_HERE";
const provider = new QuickNodeProvider()
const wallet = new Wallet(privateKey, provider)
const signer = new EvmSigner(wallet)
const subAccount = new BitSubAccount({account: 'jeff.makeafriend.bit', signer});
const result = await subAccount.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 Second-level DID.
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 { EvmSigner } = require('dotbit')
const { Wallet, QuickNodeProvider } = require('ethers')
const privateKey = "INPUT_YOUR_PRIVATE_KEY_HERE";
const provider = new QuickNodeProvider()
const wallet = new Wallet(privateKey, provider)
const signer = new EvmSigner(wallet)
const subAccount = new BitSubAccount({account: 'jeff.makeafriend.bit', signer});
const result = await subAccount.updateRecords([{
key: 'profile.email',
value: 'hr@apple.com',
label: 'HR',
ttl: '3000',
}])
console.log(result);
// ...
// The printed result would be like:
{
hash: '0xadc19c5a8bd9ce963cbfc876e55a9f11b0518073114ceb967d521e695d8b41a4'
}