Skip to main content
Version: 3.4.0

Remote Signer Guide

This guide will walk you through successfully installing the API and initialising it in Remote Signer mode for Multi user modes.

The first thing we need to do is ensure that you have npm installed. You'll find instructions on how to do this here. You'll also find instructions on how to install the avn-api library.

Create an account The easiest way to create an account is to create it using a supported wallet. Supported wallets are: PolkadotJS, Subwallet, Nova, Talisman.

We Need AVT
AVT is the utility token of the Aventus network. It's required to do the below:

  1. Access the Blockchain network via the API. You need 1 AVT in your account to use the API. The AVT needs to be lifted (moved) to the Aventus Network, and there are also instructions for that too here.

  2. Transaction Fee: Note, all transactions on the AVN must be paid for using AVT, so going forward it's important for you to have some AVT in your account. There are multiple ways to purchase AVT and this page provides instructions on how to get some.

Once you have some AVT in your account, of which you can check your account balance by typing your address into the explorer here, we can now configure the Remote Signer. At the end of this guide, you should be able to, on your own, query the balance of your account using this endpoint here.

important

You can get the AVN_GATEWAY_URL for both mainnet and public testnet here.

First we install the prerequisites.

const { AvnApi, SetupMode, SigningMode } = require("avn-api");
// this helps take the suri and convert it into a signer object
const { Keyring } = require("@polkadot/keyring");
const { cryptoWaitReady } = require("@polkadot/util-crypto");
const BN = require("bn.js");

And configure other prerequisites

const keyring = new Keyring({ type: "sr25519", ss58Format: 42 });
const AVN_GATEWAY_URL = "replace with AVN_GATEWAY_URL";

const EXAMPLE_USER_ADDRESS = "5EYzWhGxbogEfwNKL52ZRDCgBxu4t8oWDFAsXXVYvH6dMQTo";

// Configure the signer function needed for the Remote Signer.
const signer = {
sign: async (data, signerAddress) => await signData(data, signerAddress),
};

Next we import an object of user seeds

// an example of how to fetch users using this script. user address as the key, and suri as the value
const userSeeds = {
"5EYzWhGxbogEfwNKL52ZRDCgBxu4t8oWDFAsXXVYvH6dMQTo":
"0x5392ca60a61aea99fce14358798de93c1bc11c3696a905718738c71fae539c24",
};

Then we initialise the API

const options = {
setupMode: SetupMode.MultiUser,
signingMode: SigningMode.RemoteSigner,
hasPayer: false,
defaultLogLevel: "error",
signer,
};

const avnSdk = new AvnApi(AVN_GATEWAY_URL, options);
async function main() {
await cryptoWaitReady();
// initialise the api sdk and return
await avnSdk.init();
return avnSdk;
}

Create a function to sign the data and return the signature

async function signData(data, signerAddress) {
const signerSuri = userSeeds[signerAddress];
const signer = keyring.addFromUri(signerSuri);
return signer.sign(data);
}

Example function to query the balance of an account

async function queryBalance(avnSdk, EXAMPLE_USER_ADDRESS) {
// The address of the user would need to be specified here.
const api = await avnSdk.apis(EXAMPLE_USER_ADDRESS);

// check the address of the user and the address of the signer inside api are the same
console.log(api.query.awtManager.signerAddress === EXAMPLE_USER_ADDRESS);

// query for the signerAddress's balance
console.log(await api.query.getAvtBalance(EXAMPLE_USER_ADDRESS));
}

Example on running the above functions

(async () => {
try {
const avnSdk = await main();
await queryBalance(avnSdk, EXAMPLE_USER_ADDRESS);
} catch (err) {
console.log(err.message);
}
})();

Full script

At the end, your full code should look like this:

const { AvnApi, SetupMode, SigningMode } = require("avn-api");
// this helps take the suri and convert it into a signer object
const { Keyring } = require("@polkadot/keyring");
const { cryptoWaitReady } = require("@polkadot/util-crypto");
const BN = require("bn.js");

const keyring = new Keyring({ type: "sr25519", ss58Format: 42 });
const AVN_GATEWAY_URL = "replace with AVN_GATEWAY_URL";

const EXAMPLE_USER_ADDRESS = "5Gdzwi2p9tA464YdN8uzVBC1Khfb7UKKo9R5fJzPfnUpE5T5";

// Configure the signer function needed for the Remote Signer.
const signer = {
sign: async (data, signerAddress) => await signData(data, signerAddress),
};

// an example of how to fetch users using this script. user address as the key, and suri as the value
const userSeeds = {
"5EYzWhGxbogEfwNKL52ZRDCgBxu4t8oWDFAsXXVYvH6dMQTo":
"0x5392ca60a61aea99fce14358798de93c1bc11c3696a905718738c71fae539c24",
};

const options = {
setupMode: SetupMode.MultiUser,
signingMode: SigningMode.RemoteSigner,
hasPayer: false,
defaultLogLevel: "error",
signer,
};

const avnSdk = new AvnApi(AVN_GATEWAY_URL, options);
async function main() {
await cryptoWaitReady();
// initialise the api sdk and return
await avnSdk.init();
return avnSdk;
}

async function signData(data, signerAddress) {
const signerSuri = userSeeds[signerAddress];
const signer = keyring.addFromUri(signerSuri);
return signer.sign(data);
}

async function queryBalance(avnSdk, EXAMPLE_USER_ADDRESS) {
// The address of the user would need to be specified here.
const api = await avnSdk.apis(EXAMPLE_USER_ADDRESS);

// check the address of the user and the address of the signer inside api are the same
console.log(api.query.awtManager.signerAddress === EXAMPLE_USER_ADDRESS);

// query for the signerAddress's balance
console.log(await api.query.getAvtBalance(EXAMPLE_USER_ADDRESS));
}

(async () => {
try {
const avnSdk = await main();
await queryBalance(avnSdk, EXAMPLE_USER_ADDRESS);
} catch (err) {
console.log(err.message);
}
})();