Split-Fee Transaction as a User
This feature is used by defining the payer details in the options
field when creating an instance of the API.
Options can include:
suri
(optional): The mnemonic or secret seed of the user i.e. sender of the transaction. If it's empty, the value is read from theAVN_SURI
environment variable.hasPayer
(optional): A user specified flag used to determine if there is a configured payer for this user. If not defined, this defaults to false and the api will treat this transaction as a "self pay" transaction, requiring the signer to pay for the gateway fees.payerAddress
(optional): The payer address for this user. Defaults to the first payer configured for this user.
const options = {
suri: "0x5392ca60a61aea99fce14358798de93c1bc11c3696a905718738c71fae539c24",
hasPayer: true,
payerAddress: "5EYzWhGxbogEfwNKL52ZRDCgBxu4t8oWDFAsXXVYvH6dMQTo",
};
Initialise the API by passing those values as options.
const API = new AVN_API("https://gateway.testnet.aventus.network/", options);
Example Implementation
- Example
- Example Output
const AVN_API = require("avn-api");
const AVN_GATEWAY_URL = "https://gateway.testnet.aventus.network/";
// Do not use this account to handle funds.
const options = {
suri: "0x226beb8ff69a053e0f101944d4c917819f7b9e44f1d915f3cf30dc97844262e0",
hasPayer: true,
};
const API = new AVN_API(AVN_GATEWAY_URL, options);
const AVN_RELAYER = "5Fb...yTh";
// This can be the address or public key.
const RECIPIENT_ADDRESS = "5DA...gxV";
// The token address on Ethereum.
const TOKEN_ETHEREUM_ADDRESS = "0x2a...b0e";
//amount of the token in 18 decimals.
const TOKEN_AMOUNT = "1234000000000000000"; //i.e. 1.234 of a token
async function main() {
await api.init();
let result = await api.send.transferToken(
AVN_RELAYER,
RECIPIENT_ADDRESS,
TOKEN_ETHEREUM_ADDRESS,
TOKEN_AMOUNT
);
// Returns a request id
console.log(result);
}
(async () => {
await main();
})();
# UUID returned by the Gateway
f1710fe7-141f-43c1-b1bb-6ec33d9b3e9a