Staking
What is staking?
Staking is a way to lock your tokens to help the blockchain network or applications run smoothly. In return, you may earn rewards or contribute to the stability of the system. Think of it like putting your money in a savings account: you're helping the system grow, and sometimes you earn interest.
How does staking work?
In our system, staking works a bit differently depending on where you stake your tokens:
Staking in the consensus app
What it does: AIN Blockchain adopts the PoS consensus algorithm. The staking amount in the 'consensus' app is used to create new blocks on the blockchain.
What you get: You earn rewards based on the blocks created.
Why it's important: It secures the blockchain and keeps it running smoothly.
Staking in other apps
What it does: Your tokens provide the resources needed to write data to the blockchain.
What you get: Rewards depend on the app developer's decision. Some apps may offer rewards, while others may not.
Why it's important: It keeps the apps functional and contributes to the ecosystem.
How is this different from other blockchain?
In other blockchain, you lock your tokens to help the network and earn rewards like new tokens or fees.
In our blockchain, you can do more:
Earn rewards: By staking in the consensus app, you earn rewards for block production.
Support apps: By staking in other apps, you support their operations with rewards depending on the app developer's choice.
This gives you the choice to either focus on earning rewards or supporting the ecosystem.
How to stake?
In our system, there are two main methods to stake your tokens: using ain-js or blockchain tools. Both methods are straightforward and easy to use.
Method 1: Using ain-js
Install ain-js Make sure you have Node.js and ain-js installed.
Stake your tokens
Use the following example code to connect to the blockchain and stake tokens:
Confirm the transaction
Method 2: Using blockchain tools
If you prefer a simpler, non-programming method, you can use the pre-built script available in our repository.
Download the repository
Set up the environment Make sure you have Node.js installed. Install any dependencies by running:
Run the staking script Use the provided sendStakeTx.js script to stake your tokens:
Replace the placeholders with your own values:
<BLOCKCHAIN_API_ENDPOINT>
: The endpoint of the blockchain API. (e.g. testnet: 'https://testnet-api.ainetwork.ai', mainnet: 'https://mainnet-api.ainetwork.ai')<CHAIN_ID>
: The ID of the chain. (0: testnet, 1: mainnet)<APP_NAME>
: The name of the app.<STAKING_AMOUNT>
: The amount of tokens to stake.<ACCOUNT_TYPE>
: The type of the account: private_key, mnemonic, keystore<KEYSTORE_FILE_PATH>
: The path to the keystore file.
Confirm the transaction
How to decide the staking amount?
To determine the right staking amount for your app, consider the following key points:
Understand resource needs
Your app requires two budgets:
Bandwidth Budget: Calculated as the number of the DB write operations needed to execute the transaction.
State Budget: Based on the memory used in the blockchain's state tree.
The more resources your app uses, the higher the staking amount required.
Dynamic allocation
The amount of state budget your app receives depends on the percentage of total staking your app contributes to the systam.
This allocation is dynamic and adjusts as the total staking changes across all apps.
Use JSON RPC API: Get State Usage
Run the
getSateUsage
method to check:Your app's current state usage.
Available resources based on your app's staking amount. (in the free tier, you can only use 5% of the total state budget)
Example command: Request:
Response:
Interpret the response:
State Usage (usage)
tree_bytes: Your app is currently using
2114
bytes of state budget.
Available State (available)
tree_bytes: You can use up to
12291542508.778091
bytes of state budget.
Staking Details (staking)
app: Your app has staked
50500000
tokens.total: The total staking amount in the system is
10168575.540000014
tokens.
How to decide staking
If
usage.tree_byte
is close toavailable.tree_bytes
, your app is nearing its limit.Increase your staking amount of
app
to get more state budget.Keep monitoring the state usage to ensure your app has enough resources.
Last updated