Getting Started

Welcome to the JavaScript Cryptoasset Wallet documentation. This guide will serve to help you get started with the various modules and functionality in an existing NodeJS project.

Note

React Native and web specific instructions coming soon…

Let’s get started.

Installation

First off, we’ll need to install and save the SDK package to your project dependencies::

npm install --save cryptoasset-wallet

Note

To install the package from a private Gemfury registry, follow the instructions here: https://gemfury.com/help/npm-registry/

Creating a Wallet

We first need to create an instance of a Wallet. This wallet will provide all the functionality we need to create and work with managed accounts. To achieve this, we can use the createWallet factory function.

1
2
3
4
const { createWallet } = require('cryptoasset-wallet')

const rootSeed = '86bd966a3bb5f6e9c28166c95f2bb7ca4e0f55d62399e6d27baaf6855de4d73178c6bd8da57f3d62fcca1b94873c25b77c557e07892fd26191d42b9d48ecea85'
const wallet = createWallet(rootSeed)

The rootSeed specified above is an example of a 512-bit BIP39 seed generated from the following mnemonic phrase

glare exile skill cinnamon vehicle blossom join argue crash rent way layer yellow web future

Going forward, all accounts created through this wallet will represent children nodes at some path relative to the root seed provided in this step.

Generating an Account

An Account acts as a derivative node of the wallet that contains its own set of keys. An account will either need to be created for Pl^g or Ethereum which will then dictate the accounts curveType.

Let’s initialize an account to be managed by our wallet created above. After the wallet creation code, initialize a Pl^g account using the following:

1
 const myPlugAccount = wallet.generatePlugAccount()

Now that our account is initialized, it can be accessed through either the myPlugAccount variable, or through the accounts collection on the Wallet instance.

Let’s print out the public address of our new account:

1
 console.log("My plug account address is", myPlugAccount.address)

This will output an address of 1Ps7Ky8rJbXQ3pVbi9yXpfMGWDBaEPgMve. Setting up an Asset ~~~~~~~~~~~~~~~~~~~~

Now that we have a Plug account, we need to add the assets that we are interested in.

We are going to add the CENNZ asset. In order to do this, we will use Account.addAsset()

1
 myPlugAccount.addAsset('CENNZ')

Note

Per-asset implementation and configuration details are bound to change regularly, and will be documented in the Changelog page.

Now that we have added the CENNZ asset to our account, we can request the current CENNZ balance represented by this account as follows:

1
2
 const balance = await myPlugAccount.assets.CENNZ.fetchBalance()
 console.log("My plug account balance is", balance)

Sending a Payment

Now that our account has been setup successfully, it’s time to send a balance transfer to another account.

We must provide a transfer parameters object to the send method. Firstly we must provide a to address to specify the receiver of our balance, and secondly we must provide an amount that we wish to send:

Note

All balances will be in the smallest representation of that currency. This depends entirely on the selected asset, however we can convert to the major unit or the minor unit using the asset’s methods //TODO link

1
2
3
4
 const transfer = myPlugAccount.send({
     to: '139fWD3dYQsjKri7VHqnkn42jHg5TkiMPS',
     amount: 1e16 // 0.01 ETH
 })

Once we have successfully submitted the transfer, we can wait for confirmation or rejection of our payment from the network:

1
2
3
 console.log("transfer has been successfully submitted")
 console.log("My updated Ethereum balance is", await myEthAccount.fetchBalance())
 console.log("transfer has been confirmed")

Next Steps

That’s it for this guide. You’ll find the full suite of functionality documented in the Reference pages.