Create an Account

Create a New Account

Call create_account to create a new account

 const response = await fetch('http://localhost:9090/wallet/v2', {
   method: 'POST',
   body: `{
     "method": "create_account",
     "params": {
         "name": "Joshua Goldbard",
     },
     "jsonrpc": "2.0",
     "id": 1
 }`,
   headers: {
     'Content-Type': 'application/json'
   }
 });
 const myJson = await response.json();
 account = myJson.result.account

This method will return a number of parameters including the accounts id, the main_address to receive assets, and the first_block_index.

To protect yourself from ever losing your the associated funds in the account, run export_account_secrets using the * account_id* from the previous step to show the secret mnemonic that can be used to import the account again

 const response = await fetch('http://localhost:9090/wallet/v2', {
   method: 'POST',
   body: `{
     "method": "export_account_secrets",
     "params": {
         "account_id": "b504409093f....2d87a35d02c",
     },
     "jsonrpc": "2.0",
     "id": 1
 }`,
   headers: {
     'Content-Type': 'application/json'
   }
 });
 const myJson = await response.json();
 account_secrets = myJson.result.account_secrets;

An account's secret mnemonic is extremely sensitive and anyone with this information will be able to see and spend from your account! Please use best practices for securing and storing this information as without it you will lose all access to your account and funds.

Import an Existing Account

If you already have an account, you can access it with the import_account method.

 const response = await fetch('http://localhost:9090/wallet/v2', {
   method: 'POST',
   body: `{
     "method": "import_account",
     "params": {
        "mnemonic": "sheriff odor square mistake huge skate mouse shoot purity weapon proof stuff correct concert blanket neck own shift clay mistake air viable stick group",
        "key_derivation_version": "2",
        "first_block_index": "1200000"
     },
     "jsonrpc": "2.0",
     "id": 1
   }`,
   headers: {
     'Content-Type': 'application/json'
   }
 });
 const myJson = await response.json();
 account = myJson.result.account;

If you have an account that was created before the use of mnemonics, please use the Import From Legacy Root Entropy api call.

To identify your account, you must provide the method with your secret mnemonic and an account name to be used, however the name parameter is optional

To speed up the import process, you can provide the method with the first block index that you'd like to scan from the ledger. If you don’t include the first block index, it will default to scanning the entire ledger, which will take longer as the ledger size increases.

Last updated