Example Usage
The Sei precompiles can be used like any standard smart contract on the EVM. For example, using ethers.js , you can interact with Sei’s staking module via the staking precompile.
Setup
To install ethers
and the Sei EVM bindings, run:
npm install ethers
npm install @sei-js/evm
Next, import the staking precompile’s address and ABI:
// Import Staking precompile address and ABI
// View the entire ABI here: https://github.com/sei-protocol/sei-chain/tree/evm/precompiles/staking
import { STAKING_PRECOMPILE_ABI, STAKING_PRECOMPILE_ADDRESS } from '@sei-js/evm';
Using the contract
Set up your provider, signer, and contract instance:
import { ethers } from 'ethers';
// Using MetaMask as the signer and provider
const provider = new ethers.BrowserProvider(window.ethereum);
await provider.send('eth_requestAccounts', []);
const signer = await provider.getSigner();
// Create a contract instance for the staking precompile
const staking = new ethers.Contract(STAKING_PRECOMPILE_ADDRESS, STAKING_PRECOMPILE_ABI, signer);
Delegate tokens
// Sei validator address you want to delegate to
const validatorAddress = 'seivaloper1xyz...';
// Delegate 1 SEI (convert to 1 SEI = 1_000_000_000_000_000_000 wei = 10^18 wei)
const amountToDelegate = ethers.parseUnits('1000000000000000000', 0);
const tx = await staking.delegate(validatorAddress, { value: amountToDelegate });
const receipt = await tx.wait();
console.log('Delegation completed:', receipt);
Query a delegation
// Get your EVM address as the delegator
const delegator = await signer.getAddress();
const delegationInfo = await staking.delegation(delegator, validatorAddress);
console.log('Delegation details:', {
amount: delegationInfo.balance.amount.toString(),
denom: delegationInfo.balance.denom,
shares: delegationInfo.delegation.shares.toString()
});
Last updated on