All Products
Search
Document Center

Account Interface

Last Updated: May 24, 2019

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.

    1. chain.ctr.CreateAccount({
    2. from: 'Tester001',
    3. to: 'Tester002',
    4. data: {
    5. recover_key: '0xf5e50510a04a3f659a0e89f2063f79f8c1aed5ddaab6420ac47700020d9889dc14dae4dc9843c88d8222167095d9e6ce052e8a19cbc737c3f3cddf66409dbb0a',
    6. auth_key: '0xf5e50510a04a3f659a0e89f2063f79f8c1aed5ddaab6420ac47700020d9889dc14dae4dc9843c88d8222167095d9e6ce052e8a19cbc737c3f3cddf66409dbb0a',
    7. auth_weight: 100
    8. }
    9. }, (err, data) => {
    10. console.log(data)
    11. })
  • Use the newly created key to create an account.

    1. const newKey = Chain.utils.generateECKey();
    2. console.log('newKey priKey:', newKey.privateKey.toString('hex'))
    3. console.log('newKey pubKey:', newKey.publicKey.toString('hex'))
    4. chain.ctr.CreateAccount({
    5. from: 'Tester001',
    6. to: 'Tester003',
    7. data: {
    8. recover_key: '0x'+ newKey.publicKey.toString('hex'),
    9. auth_key: '0x'+ newKey.publicKey.toString('hex'),
    10. auth_weight: 100
    11. }
    12. }, (err, data) => {
    13. console.log(data)
    14. })

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

  1. chain.ctr.TransferBalance({
  2. from: 'Tester001',
  3. to: 'Tester002',
  4. value: 0
  5. }, (err, data) => {
  6. console.log(data)
  7. })

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

  1. chain.ctr.SetRecoverkey({
  2. from: account,
  3. data: {
  4. recover_key: publicKey
  5. }
  6. }, (err, data) => {
  7. console.log(data)
  8. })

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

  1. chain.ctr.PreResetPubKey({
  2. from: 'Tester001'
  3. }, (err, data) => {
  4. console.log(data)
  5. })

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

  1. chain.ctr.ResetPubKey({
  2. from: 'Tester001',
  3. data: {
  4. auth_key:'0xf5e50510a04a3f659a0e89f2063f79f8c1aed5ddaab6420ac47700020d9889dc14dae4dc9843c88d8222167095d9e6ce052e8a19cbc737c3f3cddf66409dbb0a',
  5. auth_weight: 100,
  6. }
  7. }, (err, data) => {
  8. console.log(data)
  9. })

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

  1. chain.ctr.UpdateAuthMap({
  2. from: 'Tester001',
  3. data: {
  4. auth_key:'0xf5e50510a04a3f659a0e89f2063f79f8c1aed5ddaab6420ac47700020d9889dc14dae4dc9843c88d8222167095d9e6ce052e8a19cbc737c3f3cddf66409dbb0a',
  5. auth_weight: 100,
  6. }
  7. }, (err, data) => {
  8. console.log(data)
  9. })