The JavaScript (JS) SDK account interface provides six operations for managing blockchain accounts: creating accounts, transferring balances, and managing cryptographic keys.
Key concepts
Name-based accounts — Accounts on this blockchain are identified by name strings (such as 'Tester001'), not by cryptographic addresses. The from and to parameters in each operation are account names.
Two-key model — Each account holds two distinct keys:
Auth key (
auth_key): The key used to authorize transactions. UseResetPubKeyto replace it.Recovery key (
recover_key): A backup key for account recovery. UseSetRecoverkeyto update it.
Weight — The current JS SDK supports only one auth key per account. Set auth_weight to 100. If multiple auth keys are supported in a future release, the weights of all auth keys must sum to 100.
Never share or store private keys in plaintext. Store key material in environment variables or a secrets manager.
Create accounts
Call CreateAccount to create a new account on the blockchain.
Parameters
All parameters are passed as a single object.
| Parameter | Required | Type | Description |
|---|---|---|---|
from | Yes | string | The account name used to create the new account. |
to | Yes | string | The name of the new account. |
data | Yes | object | Key material for the new account. See the data fields below. |
`data` fields:
| Field | Required | Type | Description |
|---|---|---|---|
recover_key | No | string | A 0x-prefixed hex string, 64 bytes excluding the 0x prefix. |
auth_key | No | string | A 0x-prefixed hex string, 64 bytes excluding the 0x prefix. |
auth_weight | No | string | Weight of the auth key. Set to 100. |
Examples
Use an existing public key
chain.ctr.CreateAccount({
from: 'Tester001',
to: 'Tester002',
data: {
recover_key: '0xf5e50510a04a3f659a0e89f2063f79f8c1aed5ddaab6420ac47700020d9889dc14dae4dc9843c88d8222167095d9e6ce052e8a19cbc737c3f3cddf66409dbb0a',
auth_key: '0xf5e50510a04a3f659a0e89f2063f79f8c1aed5ddaab6420ac47700020d9889dc14dae4dc9843c88d8222167095d9e6ce052e8a19cbc737c3f3cddf66409dbb0a',
auth_weight: 100
}
}, (err, data) => {
console.log(data)
})Generate a new EC key pair
Use Chain.utils.generateECKey() to create a new key pair and use its public key for both recover_key and auth_key.
const newKey = Chain.utils.generateECKey();
console.log('Private key:', newKey.privateKey.toString('hex'))
console.log('Public key:', newKey.publicKey.toString('hex'))
chain.ctr.CreateAccount({
from: 'Tester001',
to: 'Tester003',
data: {
recover_key: '0x' + newKey.publicKey.toString('hex'),
auth_key: '0x' + newKey.publicKey.toString('hex'),
auth_weight: 100
}
}, (err, data) => {
console.log(data)
})Transfer balances
Call TransferBalance to transfer funds from one account to another.
Parameters
All parameters are passed as a single object.
| Parameter | Required | Type | Description |
|---|---|---|---|
from | Yes | string | The source account name. |
to | Yes | string | The destination account name. |
value | Yes | number | The limit of the transfer amount. |
Example
chain.ctr.TransferBalance({
from: 'Tester001',
to: 'Tester002',
value: 0
}, (err, data) => {
console.log(data)
})Set the recovery key
Call SetRecoverkey to set or update the recovery key for an account.
Parameters
All parameters are passed as a single object.
| Parameter | Required | Type | Description |
|---|---|---|---|
from | Yes | string | The account to update. |
data | Yes | object | Recovery key data. See the data fields below. |
`data` fields:
| Field | Required | Type | Description |
|---|---|---|---|
recover_key | Yes | string | A 0x-prefixed hex string, 64 bytes excluding the 0x prefix. |
Example
chain.ctr.SetRecoverkey({
from: account,
data: {
recover_key: publicKey
}
}, (err, data) => {
console.log(data)
})Pre-reset the public key
Call PreResetPubKey to initiate a public key reset for an account.
Parameters
All parameters are passed as a single object.
| Parameter | Required | Type | Description |
|---|---|---|---|
from | Yes | string | The account whose public key will be reset. |
Example
chain.ctr.PreResetPubKey({
from: 'Tester001'
}, (err, data) => {
console.log(data)
})Reset the public key
Call ResetPubKey to replace the auth key for an account.
Parameters
All parameters are passed as a single object.
| Parameter | Required | Type | Description |
|---|---|---|---|
from | Yes | string | The account whose auth key will be replaced. |
data | Yes | object | The new auth key data. See the data fields below. |
`data` fields:
| Field | Required | Type | Description |
|---|---|---|---|
auth_key | Yes | string | A 0x-prefixed hex string, 64 bytes excluding the 0x prefix. |
auth_weight | Yes | number | Weight of the auth key. Set to 100. If multiple auth keys are supported in a future release, the sum of all weights must equal 100. |
Example
chain.ctr.ResetPubKey({
from: 'Tester001',
data: {
auth_key: '0xf5e50510a04a3f659a0e89f2063f79f8c1aed5ddaab6420ac47700020d9889dc14dae4dc9843c88d8222167095d9e6ce052e8a19cbc737c3f3cddf66409dbb0a',
auth_weight: 100,
}
}, (err, data) => {
console.log(data)
})Update key weights
Call UpdateAuthMap to update the weight of a public key for an account.
Parameters
All parameters are passed as a single object.
| Parameter | Required | Type | Description |
|---|---|---|---|
from | Yes | string | The account to update. |
data | Yes | object | The updated auth key data. See the data fields below. |
`data` fields:
| Field | Required | Type | Description |
|---|---|---|---|
auth_key | Yes | string | A 0x-prefixed hex string, 64 bytes excluding the 0x prefix. |
auth_weight | Yes | number | Weight of the auth key. Set to 100. If multiple auth keys are supported in a future release, the sum of all weights must equal 100. |
Example
chain.ctr.UpdateAuthMap({
from: 'Tester001',
data: {
auth_key: '0xf5e50510a04a3f659a0e89f2063f79f8c1aed5ddaab6420ac47700020d9889dc14dae4dc9843c88d8222167095d9e6ce052e8a19cbc737c3f3cddf66409dbb0a',
auth_weight: 100,
}
}, (err, data) => {
console.log(data)
})