Initialise API
Now that we have the API installed, we can initialise the API. There are two ways to initialise the API:
- Offline Mode
- Online Mode
Offline mode exposes the AWT token generation and signature proof generation required to configure JSON-RPC calls, along with account generation tools found here. To run the API in offline mode, have this at the top of your code:
const AVN_API = require('avn-api');
const API = new AVN_API();
await API.init();
Passing a gateway URL enables the full, connected api:
const AVN_API = require('avn-api');
const API = new AVN_API("https://testnet.gateway.aventus.io/");
await API.init();
You can get the AVN_GATEWAY_URL here.
When creating an instance of the API, an optional options paramater can also be passed in. Options can include:
suri
(optional): The mnemonic or secret seed of the user/sender. If empty the value is read from the AVN_SURI environment variable. More info on SURI here.hasPayer
(optional): A user specified flag used to determine if there is a configured payer for this user. Defaults to false. More info on payer here.payerAddress
(optional): The payer address for this user. Defaults to the first payer configured for this user. More info on payer here.relayer
(optional): The relayer to use to process transactions. Defaults to Aventus. More info on relayers here.
Example
const options = { suri: '0x226beb8ff69a053e0f101944d4c917819f7b9e44f1d915f3cf30dc97844262e0', hasPayer: false, relayer: '5FbUQ2kJWLoqHuSTSNNqBwKwdQnBVe4HF3TeGyu6UoZaryTh' }
const API = new AVN_API('https://testnet.gateway.aventus.io/', options);
This account (user/sender) being initialised must have a minimum balance of 1 AVT to access the Gateway.
There are some other params that are accepted in options
, See here for the new split-fee functionality.