Watch the video walkthrough for this topic in the Video Tutorials section.
0x0000000000000000000000000000000000001005
The Sei staking precompile allows EVM applications to interact directly with Sei’s native staking module through standard smart contract calls. This enables delegation, undelegation, redelegation, validator management, and staking queries directly from your dApps without needing separate Cosmos SDK integration.
What is a precompile? A precompile is a special smart contract deployed at a fixed address by the Sei protocol itself, that exposes custom native chain logic to EVM-based applications. It acts like a regular contract from the EVM’s perspective, but executes privileged, low-level logic efficiently.
How Does the Staking Precompile Work?
The staking precompile at address0x0000000000000000000000000000000000001005 exposes a comprehensive set of staking functions including delegate(), undelegate(), redelegate(), createValidator(), editValidator(), and various query functions like validators(), delegatorDelegations(), pool(), and params().
- Direct Integration: EVM contracts and dApps can call staking functions like any other smart contract method.
- Native Execution: Operations are executed at the Cosmos SDK level for maximum efficiency and security.
- Seamless Bridge: No need for separate wallet integrations or complex cross-chain interactions.
- Event Emission: All staking operations emit events (
Delegate,Undelegate,Redelegate,ValidatorCreated,ValidatorEdited) for easy tracking and indexing.
Use Cases
- DeFi Integration: Build liquid staking protocols and yield farming strategies.
- Delegation Services: Create user-friendly interfaces for staking operations.
- Portfolio Management: Automate staking strategies and delegation rebalancing.
- Validator Management: Create and manage validators programmatically.
What You’ll Learn in This Guide
By the end of this guide, you’ll be able to:- Integrate Staking Operations - Call delegation, undelegation, and redelegation functions directly from your EVM contracts and dApps
- Handle Decimal Precision - Master the critical precision patterns for different operations to avoid common formatting errors
- Create and Manage Validators - Create new validators and edit their parameters programmatically
- Query Staking State - Use the comprehensive query functions to fetch validators, delegations, unbonding info, pool statistics, and staking parameters
- Listen for Staking Events - Track staking operations using emitted events for indexing and notifications
- Build Portfolio Tools - Implement automated rebalancing and delegation tracking for staking management applications
- Navigate Staking Risks - Understand unbonding periods, slashing mechanics, and validator selection for safe staking operations
Events
The staking precompile emits the following events:Listening for Events
You can listen for these events in your dApp to track staking operations:Functions
The staking precompile exposes the following functions:Transaction Functions
Query Functions
Using the Precompile
Setup
Prerequisites
Before getting started, ensure you have:- Node.js (v18 or higher)
- npm or yarn package manager
- EVM-compatible wallet
- SEI tokens for gas and staking operations
Install Dependencies
Install the required packages for interacting with Sei precompiles:Import Precompile Components
Precompile Address: The staking precompile is deployed at
0x0000000000000000000000000000000000001005 Contract Initialization
Set up your provider, signer, and contract instance:Critical: Understanding Decimal Precision
One of the most important concepts to understand when working with the Sei staking precompile:Mixed Decimal Precision System
The staking precompile operates with different decimal precision for different operations due to bridging EVM and Cosmos standards:How This Works in Practice
delegate() Function (Uses 18 decimals):delegate()- acceptsmsg.valuein wei (18 decimals)
undelegate()- expects amount parameter in 6 decimals (uSEI)redelegate()- expects amount parameter in 6 decimals (uSEI)
delegation()- returnsbalance.amountin 6-decimaluSEIanddelegation.sharesin 18-decimal precision- Rewards are handled by the Distribution precompile:
rewards()query returns 18-decimalDecCoins, while withdrawn amounts (events) are 6-decimaluSEI
Why This Mixed System Exists
- delegate() EVM Compatibility: Uses standard 18-decimal wei format for EVM
msg.valueconsistency - Other Operations Cosmos Integration:
undelegate()andredelegate()use 6-decimal uSEI precision to match native Cosmos operations - Staking Query Consistency: Staking precompile query balances use 6-decimal
uSEI(whilesharesis 18-decimal) for consistent reading
Best Practice: Different Conversion for Different Functions
When working with user inputs, use the appropriate conversion for each function:Normalization Guidelines (Clients and Indexers)
- Normalize to a single unit for analytics and reconciliation:
- Display: convert to
SEI(wei / 1e18,uSEI / 1e6) - Storage/aggregation: prefer
uSEI(6 decimals)
- Display: convert to
- Reconciling delegate vs. undelegate/redelegate/rewards: convert delegate
msg.valuefrom wei to uSEI using integer division by1e12(floor), which matches the precompile’s internal truncation. - Enforce granularity at source: construct
msg.valueas a multiple of1e12wei by formatting user input to 6 decimals prior toparseUnits.
Decimal Conversion Helpers
Use these helper functions to avoid precision errors:Step-by-Step Guide: Using the Staking Precompile
Delegate Tokens
- JavaScript
- Solidity
Undelegate Tokens
- JavaScript
- Solidity
Redelegate Tokens
- JavaScript
- Solidity
Query a Delegation
- JavaScript
- Solidity
Create a Validator
- JavaScript
- Solidity
Edit a Validator
Edit Validator Constraints: - Commission can only be changed once every 24 hours -
minSelfDelegation can only be increased, never decreased - Pass empty string "" for commissionRate to keep current rate - Pass 0 for minSelfDelegation to keep current valueQuery Validators
Query a Specific Validator
Query All Delegations for an Address
Query Unbonding Delegations
Query Redelegations
Query Staking Pool and Parameters
Query Historical Validator Info
Advanced Usage Examples
Portfolio Rebalancing
Complete Integration Example
- JavaScript
- Solidity
Security Considerations & Risks
Unbonding Period
- 21-day lock: Undelegated tokens cannot be transferred or earn rewards for 21 days
- No exceptions: This cannot be canceled once initiated
- Planning: Consider this when managing liquidity needs
Validator Selection Criteria
- Commission Rate: Lower commission means more rewards for you (typically 1-10%)
- Uptime: Check for validators with high uptime (99%+)
Redelegation Complexity
- 7-transaction limit: You can only redelegate from the same validator to the same destination validator 7 times in 21 days
- Serial blocking: After redelegating A→B, you cannot redelegate B→C for 21 days
- Each redelegation starts its own 21-day timer
Troubleshooting
Common Issues and Solutions
Gas-Related Issues
Error Code Reference
FAQ: Precision and Normalization
- What are the base units and precision standards defined for SEI across operations?
delegate(): acceptsmsg.valuein wei (18 decimals), but is internally truncated to 6-decimaluSEI. Effective granularity is 1 uSEI =1e12wei.undelegate()/redelegate(): amounts use 6-decimaluSEI.- Staking queries: balances are 6-decimal
uSEI(and shares are 18-decimal). Distributionrewards()query returns 18-decimalDecCoins, but withdrawn amounts are 6-decimaluSEI.
- Should applications normalize between 18 and 6 decimals?
- Yes. For reconciliation, convert delegate
weitouSEIvia integer division by1e12(floor). For display, convert to SEI (wei → /1e18,uSEI → /1e6).
- Yes. For reconciliation, convert delegate
- Is this behavior consistent and intentional?
- Yes. This is intentional and not planned to change. Delegation uses EVM-native
msg.value(18 decimals), while staking operations are executed in the Cosmos staking module, which uses 6-decimaluSEI.
- Yes. This is intentional and not planned to change. Delegation uses EVM-native
- Why multiple decimal precisions on one chain?
- To bridge EVM conventions (18-decimal
msg.value) with the Cosmos staking module’s native 6-decimal accounting while keeping queries and non-delegate()writes consistent at 6 decimals.
- To bridge EVM conventions (18-decimal
Important Notes
Remember the key rule: delegate() uses 18 decimals, undelegate()/redelegate() use 6 decimals, delegation() returns 6 decimals!
Decimal Precision
- delegate() uses 18 decimals (wei) for msg.value
- undelegate() and redelegate() use 6 decimals (uSEI) for amount parameters
- Query results return amounts in 6 decimal precision
- Best practice: Use appropriate conversion functions for each operation
- Rewards/claims (Distribution precompile):
rewards()query returns 18-decimalDecCoins; withdrawn amounts (events) are 6-decimaluSEI - Granularity:
delegate()msg.valuemust be a multiple of1e12wei (last 12 digits zero) because the precompile truncates to 6 decimals internally
Validator Addresses
- Use valid Sei validator addresses with
seivaloper1...prefix - These are Cosmos-format addresses, not EVM addresses
Staking Risks
- Unbonding: 21-day waiting period for undelegated tokens
- Redelegation limits: Complex rules around frequency and serial operations
Commission and Rewards
- Validators keep a commission percentage
- Rewards are distributed proportionally to delegation amounts
- Choose validators wisely based on commission, uptime, and governance participation