Stake AVT
Stakes the specified amount of AVT, locking its free usage in order to earn rewards.
First time stakers must stake a minimum of 100 AVT.
await api.send.stake(AMOUNT_TO_STAKE);
- JS Example
- Example Result
const { AvnApi, SetupMode, SigningMode } = 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);
//Amount of AVT in 18 decimals
const AMOUNT_TO_STAKE = "1000000000000000000";
async function main() {
await avnSdk.init();
const api = await avnSdk.apis();
let result = await api.send.stake(AMOUNT_TO_STAKE);
// Returns a request id
console.log(result);
}
(async () => {
await main();
})();
You have now successfully submitted a transaction to the AVN.
f1710fe7-141f-43c1-b1bb-6ec33d9b3e9a
You can query the state of your transaction here using the returned request id.
JSON-RPC
There are two JSON-RPC methods to staking AVT.
proxyStakeAvt
- Only to be used for first time stakers.proxyIncreaseStake
Only to be used for current stakers.
- First Time Stakers - STAKE
- JSON-RPC Output
- Current Stakers JSON-RPC - Stake
- JSON-RPC Output
"method":"proxyStakeAvt"
REQUEST
POST <https://AVN_GATEWAY_URL/send>
HEADERS
Content-Type: application/json Authorization': bearer <awtToken>
The initial staking requires 2 sets of proofs, one to cover the bonding step and one to cover the nominating step
REQUEST PARAMS
- relayer [required] - a string representing the relayer's SS58 address
- user [required] - a string representing the user's SS58 address
- payer [required] - a string representing the payer's SS58 address
- amount [required] - a string integer value representing the full amount of AVT to stake
- targets [required] - The list of validators to nominate
- nonce [required] - string integer value of the current proxy nonce of type 'staking'
- proxySignature [required] - a proof signed by the user allowing the transaction to be proxied
- feePaymentSignature [required] - a proof signed by the payer allowing the relayer fees to be paid
- paymentNonce [required] - string integer value of the current payment nonce of the payer
JSON-RPC Example
curl https://AVN-API-URL/send \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: bearer <awtToken>" \
-d '{"jsonrpc":"2.0", "method":"proxyStakeAvt", "params":{"relayer": "5FbUQ...F3TeGyu6UoZaryTh",
"user": "5HMYezk4gRAoed...p7DGZM8rSTyf", "payer": "5HMYezk4gRAoed...p7DGZM8rSTyf",
"amount": "51000000000000000000", "targets": ["5CB8eZjJraPR7e...UHYUAG7HbnR", "5DHXA2pDmGM...zNw6EpBe9GgHKkunkL",
"5F6tYYDzZvGk...mUqSb3Q85nmkRa7JSMj", "5GNCn4Tyb3sgCF9...AZQWF1N1ikyVV",
"5HdTonR7WyEtwAR...1jzXXnzdgknViqiYyh"], "nonce": "112",
"proxySignature": "0x3c9d46239bb5426c9d253a2404c6444a12...7f055b93dd74ed9bb79a8ff10fe1343a4130602bdf32b2010b48d",
"feePaymentSignature": "0x82603b6dd7d63101a93db4402b57792443d1068...4ab61ff13ac81285bdc1304435a9338ade873bc84",
"paymentNonce": "10071"}, "id":1}'
result 👇🏽 - a request ID that can be queried for the transaction's status
{
"jsonrpc": "2.0",
"id": 1,
"result": "8f7f76c8-a06e-11ec-b909-0242ac120002"
}
"method":"proxyIncreaseStake"
REQUEST
POST <https://AVN_GATEWAY_URL/send>
HEADERS
Content-Type: application/json Authorization': bearer <awtToken>
REQUEST PARAMS
- relayer [required] - a string representing the relayer's SS58 address
- user [required] - a string representing the user's SS58 address
- payer [required] - a string representing the payer's SS58 address
- amount [required] - a string integer value representing the full amount of AVT to stake
- nonce [required] - string integer value of the current proxy nonce of type 'staking'
- proxySignature [required] - a proof signed by the user allowing the transaction to be proxied
- feePaymentSignature [required] - a proof signed by the payer allowing the relayer fees to be paid
- paymentNonce [required] - string integer value of the current payment nonce of the payer
JSON-RPC Example
curl https://AVN-API-URL/send \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: bearer <awtToken>" \
-d '{"jsonrpc":"2.0", "method":"proxyIncreaseStake", "params":{"relayer":"5FbUQ2kJW...TeGyu6UoZaryTh", "user":"5DAgxVxKmnJ...rSVJDdMr", "payer":"5DAgxVxKmnJ...rSVJDdMr", "amount":"1000000", "nonce":"113", "proxySignature":"0x4bd139e3ac19d8fe217574c138ca...49b4fbb6df2d96e579af68d6643c1cd4234812f8c9adb0e102a5840145", "feePaymentSignature":"0x123ad5e9df7e5443b29de409e56687...12b27e75847f8e5d056a996b4186d0ee80b3eb05ef0d1991c05539b0c8", "paymentNonce":"305"}, "id":1}'
result - a request ID that can be queried for the transaction's status
{
"jsonrpc": "2.0",
"id": 1,
"result": "8f7f76c8-a06e-11ec-b909-0242ac120002"
}
Validation
This endpoint can only be called while the eraElectionWindow
is closed. If it is called during an election, the following error response will be returned:
{
"code":-32600,
"message":"Invalid Request",
"data": {
"gatewayError":"election window is open",
"request":"{...}"
}