Create accounts
You can call the CreateAccount
operation to create a new account on a blockchain.
Request parameters
The following parameters are encapsulated and passed in as an object.
Name | Required | Type | Description |
---|---|---|---|
from | true | string | The account name that is used to create a new account. |
to | true | string | The name of the new account that is created. |
data | true | object | The data content, including the data required to create a new account. |
Content of the data field:
Field | Required | Type | Description |
---|---|---|---|
recover_key | false | string | A hex string starting with “0x” with a length of 64 bytes (not including “0x”). |
auth_key | false | string | A hex string starting with “0x” with a a length of 64 bytes (not including “0x”). |
auth_weight | false | string | The JS SDK supports only one auth key. Set the weight value to 100. |
Examples
Use a created public key to create an account.
chain.ctr.CreateAccount({
from: 'Tester001',
to: 'Tester002',
data: {
recover_key: '0xf5e50510a04a3f659a0e89f2063f79f8c1aed5ddaab6420ac47700020d9889dc14dae4dc9843c88d8222167095d9e6ce052e8a19cbc737c3f3cddf66409dbb0a',
auth_key: '0xf5e50510a04a3f659a0e89f2063f79f8c1aed5ddaab6420ac47700020d9889dc14dae4dc9843c88d8222167095d9e6ce052e8a19cbc737c3f3cddf66409dbb0a',
auth_weight: 100
}
}, (err, data) => {
console.log(data)
})
Use the newly created key to create an account.
const newKey = Chain.utils.generateECKey();
console.log('newKey priKey:', newKey.privateKey.toString('hex'))
console.log('newKey pubKey:', 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)
})
Transfers
You can call the TransferBalance
operation to transfer funds from one account to another account.
Request parameters
The following parameters are encapsulated and passed in as an object.
Name | Required | Type | Description |
---|---|---|---|
from | true | string | The name of the account that is used. |
to | true | string | The name of the target account. |
value | true | number | The limit of the transfer amount. |
Examples
chain.ctr.TransferBalance({
from: 'Tester001',
to: 'Tester002',
value: 0
}, (err, data) => {
console.log(data)
})
Set recovery keys
You can call the SetRecoverkey
operation to set the recovery key for an account.
Request parameters
The following parameters are encapsulated and passed in as an object.
Name | Required | Type | Description |
---|---|---|---|
from | true | string | The current account that needs to be configured. |
data | true | object | The data field. |
Content of the data field:
Field | Required | Type | Description |
---|---|---|---|
recover_key | true | string | A hex string starting with “0x” with a a length of 64 bytes (not including “0x”). |
Examples
chain.ctr.SetRecoverkey({
from: account,
data: {
recover_key: publicKey
}
}, (err, data) => {
console.log(data)
})
Pre-reset public keys
You can call the PreResetPubKey
operation to pre-reset the public key of an account.
Request parameters
The following parameters are encapsulated and passed in as an object.
Name | Required | Type | Description |
---|---|---|---|
from | true | string | The current account that needs to be configured. |
Examples
chain.ctr.PreResetPubKey({
from: 'Tester001'
}, (err, data) => {
console.log(data)
})
Reset public keys
You can call the ResetPubKey
operation to reset the public key of an account.
Request parameters
The following parameters are encapsulated and passed in as an object.
Name | Required | Type | Description |
---|---|---|---|
from | true | string | The current account that needs to be configured. |
data | true | object | The data field. |
Content of the data field:
Field | Required | Type | Description |
---|---|---|---|
auth_key | true | string | A hex string starting with “0x” with a a length of 64 bytes (not including “0x”). |
auth_weight | true | number | The value of the weight. The current JS SDK supports only one auth key, so the weight value is 100. In the future, if multiple auth keys are supported, the sum of the weight values will be 100. |
Examples
chain.ctr.ResetPubKey({
from: 'Tester001',
data: {
auth_key:'0xf5e50510a04a3f659a0e89f2063f79f8c1aed5ddaab6420ac47700020d9889dc14dae4dc9843c88d8222167095d9e6ce052e8a19cbc737c3f3cddf66409dbb0a',
auth_weight: 100,
}
}, (err, data) => {
console.log(data)
})
Update weights
You can call the UpdateAuthMap
operation to update the weights of a public key for an account.
Request parameters
The following parameters are encapsulated and passed in as an object.
Name | Required | Type | Description |
---|---|---|---|
from | true | string | The current account that needs to be configured. |
data | true | object | The data field. |
Content of the data field:
Field | Required | Type | Description |
---|---|---|---|
auth_key | true | string | A hex string starting with “0x” with a a length of 64 bytes (not including “0x”). |
auth_weight | true | number | The value of the weight. The current JS SDK supports only one auth key, so the weight value is 100. In the future, if multiple auth keys are supported, the sum of the weight values will be 100. |
Examples
chain.ctr.UpdateAuthMap({
from: 'Tester001',
data: {
auth_key:'0xf5e50510a04a3f659a0e89f2063f79f8c1aed5ddaab6420ac47700020d9889dc14dae4dc9843c88d8222167095d9e6ce052e8a19cbc737c3f3cddf66409dbb0a',
auth_weight: 100,
}
}, (err, data) => {
console.log(data)
})