Skip to main content
SUBMIT A PRSUBMIT AN ISSUElast edit: Aug 20, 2025

Staking Precompile

Staking precompile allows Ethereum code to interact with the staking feature of subtensor. For example, by using the staking precompile, the subtensor methods add_stake or remove_stake can be called in order to delegate stake to a hotkey or undelegate stake from a hotkey.

In this tutorial you will learn how to interact with staking precompile in two ways:

  1. Call the staking precompile from another smart contract.
  2. Use the staking precompile's ABI and your Metamask wallet to call the staking precompile on EVM localnet. You will use Remix IDE for this.

Prerequisites

  1. Read Bittensor EVM Smart Contracts for a basic introduction to Bittensor EVM
  2. You should also be comfortable using Remix IDE.

Setup EVM localnet, subnet and delegate

  1. Launch EVM localnet. Also, follow the instructions of running local chain all the way so that you have a Metamask address with some TAO balance.

  2. On this EVM localnet create one subnet and a delegate hotkey. The commands below will create a subnet, register a neuron and nominate your hotkey as a delegate, in that order:

btcli subnet create --network ws://127.0.0.1:9944
btcli subnet register --network ws://127.0.0.1:9944
  1. Save the delegate hotkey address. You will use this in the staking pool use case below.

  2. Disable staking rate limits by setting targetStakesPerInterval to 1000. Follow these below steps:

    • Open the Polkadot JS app using this link with encoded transaction.
    • Click on Submission tab.
    • From the using the selected account field, select ALICE.
    • Click on Submit Transaction at the bottom right. This will open the authorize transaction window.
    • On this authorize transaction window, make sure the sign and submit toggle is ON and click on the Sign and Submit on the bottom right.

Staking V1 and V2

There are two versions of staking precompile implemenation, V1 and V2. The contract address for V1 is 0x0000000000000000000000000000000000000801. The address for V2 is 0x0000000000000000000000000000000000000805. V1 is deprecated, but is kept for backwards-compatibility. The major difference between V1 and V2 is that the staking amount is fetched from the msg.value in V1. Then precompile transfers the token back to the caller. It is misleading and confuses solidity developers. In the V2 implementation, all amount parameters are defined as parameter of transaction.

Call the staking precompile from another smart contract (staking pool use case)

In this interaction you will compile stakeV2.sol, a Solidity smart contract code, and execute it on the Subtensor EVM. This stakeV2.sol will, in turn, call the staking precompile that is already deployed on the Subtensor EVM.

Before you proceed, familiarize yourself with the Solidity code of the stakeV2.sol smart contract.

  1. Copy the text of stakeV2.sol contract to Remix IDE.

  2. You will now convert your delegate hotkey ss58 from the above Setup EVM localnet, subnet and delegate step into its corresponding public key. Use the ss58.org site to obtain the public key for your delegate hotkey ss58.

  3. In the stake.sol text in Remix IDE, replace the HOTKEY constant on line 9, where it says bytes32 constant HOTKEY = 0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d;, with your delegate hotkey's public key.

  4. Compile it in Remix IDE.

  5. Connect Remix IDE to Injected Provider - Metamask and your Metamask address that has TAO balance. You will stake this TAO balance to the delegate hotkey's public key.

  6. Execute the Stake contract method stake_from_this_contract_to_alice and pass 1e^9 to it (1 TAO).

  7. Check the stake balance of your delegate hotkey and confirm that it has increased by 1 TAO.

Use the staking precompile's ABI from your user account (staking as an individual use case)

In this tutorial, you will interact directly with the staking precompile by using its ABI, and use your Metamask wallet as the source of TAO to stake.

  1. Copy the ABI from https://github.com/opentensor/subtensor/blob/main/precompiles/src/solidity/stakingV2.abi into Remix IDE as a new file.

  2. Copy staking precompile address 0x0000000000000000000000000000000000000805 to the At Address field in Remix IDE, and click At Address button.

  3. Remix IDE will find the precompile at the precompile address on the subtensor EVM and show it in the list of deployed contracts. Expand the contract, then expand the addStake method, and paste the public key of your delegate hotkey into the hotkey field. Then click transact and wait for the transaction to be completed.

  4. Follow these steps to see that the stake record is updated in Polkadot JS app:

    1. Select subtensorModule + stake in the drop-down list.
    2. Paste the delegate hotkey account ID in the first parameter.
    3. Toggle include option OFF for the second parameter.
    4. Click the + button and find the new stake record.

Notes: Calling the staking precompile from another smart contract

  • The precompile takes the contract's address as the coldkey, since the precompile can't get the original caller.
  • The contract (not the caller's coldkey) must have sufficient liquidity or the transaction will fail.
  • The transaction must be privileged because the liquidity for addStake is subtracted from contract.
  • As the function parameter indicates, amount in addStake and removeStake are specified in TAO τ\tau.
  • That when transferring liquidity to the contract, msg.value is in denominations of 1/1e18 TAO τ\tau . The staking precompile, however, expects RAO, 1/1e9 TAO τ\tau. You must convert before calling it: uint256 amount = msg.value / 1e9.