SURI
Before running any script with the avn-api, let's set your AvN mnemonic or secret seed generated via the accounts page. There are two ways you can set this:
- Environment variable
- As a Parameter when Initialising
export AVN_SURI=<mnemonic OR secret seed>
Your secret URI (SURI) could either be a mnemonic (seed phrase) or the secret seed (private key) of your account.
For windows users, here's a guide on how to set your environment variable.
Examples
You can export your SURI, in your CLI, in the format of any of the examples below
export AVN_SURI='flag dynamic laptop often park illegal equip curve game blame junior warm'
OR
export AVN_SURI=0x5392ca60a61aea99fce14358798de93c1bc11c3696a905718738c71fae539c24 // this is from the generated example account
This does not return anything.
const { AvnApi, SetupMode, SigningMode, NonceCacheType } = require("avn-api");
const AVN_GATEWAY_URL = "https://gateway.testnet.aventus.network/";
const singleUserOptions = {
suri: "0x5392ca60a61aea99fce14358798de93c1bc11c3696a905718738c71fae539c24", // this is from the generated example account
setupMode: SetupMode.SingleUser,
signingMode: SigningMode.SuriBased,
};
const avnSdk = new AvnApi(AVN_GATEWAY_URL, singleUserOptions);
async function main() {
await avnSdk.init();
const api = await avnSdk.apis();
}
There are some other params that are accepted in options
, See here for the new split-fee functionality.
If no URL is passed the API will run in offline mode, exposing ONLY core utilities and can be initialised using the below:
const avnSdk = new AvnApi(null, singleUserOptions); // null here has replaced the gateway url and configures the use as offline mode.
Throughout this document options
may be replaced with singleUserOptions
or multiUserOptions
. If you're not defining an options object, replace options
with empty curly brackets i.e. {}
.
It's important that you keep the mnemonic/seed secret safe and not expose it anywhere else. If this data is compromised, you could lose your funds.