Watch the video walkthrough for this topic in the Video Tutorials section.
0x0000000000000000000000000000000000001007
The distribution precompile provides EVM access to Cosmos SDK’s distribution module. Smart contracts can manage staking rewards, validator commissions, and withdrawal addresses. This precompile is essential for DeFi applications that need to handle staking rewards programmatically.
Key Features
- Reward Management: Withdraw delegation rewards from validators
- Commission Handling: Validators can withdraw earned commissions
- Batch Operations: Withdraw from multiple validators efficiently
- Flexible Withdrawals: Set custom withdrawal addresses
- Comprehensive Queries: Access detailed reward information
Interface Overview
Events
The distribution precompile emits events for all state-changing operations, allowing off-chain services to track reward distributions and configuration changes.WithdrawAddressSet
Emitted when a delegator changes their reward withdrawal address.delegator(indexed): The EVM address of the delegator changing their settingswithdrawAddr: The new address where rewards will be sent
DelegationRewardsWithdrawn
Emitted when a delegator withdraws rewards from a single validator.delegator(indexed): The EVM address of the delegator withdrawing rewardsvalidator: The Sei validator address (e.g., “seivaloper1…”)amount: The amount of rewards withdrawn (in usei, 6 decimal precision)
MultipleDelegationRewardsWithdrawn
Emitted when a delegator withdraws rewards from multiple validators in a single transaction.delegator(indexed): The EVM address of the delegator withdrawing rewardsvalidators: Array of Sei validator addressesamounts: Array of reward amounts corresponding to each validator (in usei, 6 decimal precision)
ValidatorCommissionWithdrawn
Emitted when a validator operator withdraws their earned commission.validator(indexed): The Sei validator addressamount: The commission amount withdrawn (in usei, 6 decimal precision)
Event Amounts: All event amounts use 6 decimal precision (usei), matching the actual withdrawn token amounts. This differs from the
rewards() query which returns 18 decimal precision.Transaction Methods
setWithdrawAddress
Sets the withdrawal address for staking rewards. By default, rewards are sent to the delegator’s address, but this can be customized.withdrawAddr: EVM address where future rewards should be sent
Fallback on Invalid Stored Address: If a previously set withdraw address later becomes unable to receive funds (for example, it becomes blocked or otherwise fails the
CanSendTo check), the distribution module falls back to sending rewards to the delegator’s own address rather than failing. Reward and commission withdrawals therefore always succeed even if the stored withdraw address is no longer valid.withdrawDelegationRewards
Withdraws accumulated rewards from a specific validator.validator: Sei validator address (e.g., “seivaloper1…”)
withdrawMultipleDelegationRewards
Efficiently withdraws rewards from multiple validators in a single transaction.validators: Array of Sei validator addresses
Batch Efficiency: Using
withdrawMultipleDelegationRewards is significantly more gas-efficient than multiple individual calls, especially when withdrawing from 3+ validators.withdrawValidatorCommission
Allows validators to withdraw their earned commission. Only callable by the validator operator address.Query Methods
rewards
Retrieves comprehensive reward information for a delegator across all validators.Understanding Decimal Precision
The distribution precompile has different decimal precision for queries vs actual withdrawals due to how rewards are tracked in the Cosmos SDK:Why Different Precisions?
-
Pending Rewards (18 decimals): The Cosmos SDK tracks pending rewards using
DecCoins(decimal coins) with 18 decimal precision for higher accuracy during reward accumulation. -
Withdrawn Rewards (6 decimals): When rewards are actually withdrawn, they are converted to
sdk.Coins(usei) with 6 decimal precision to match Sei’s native token units.
Conversion Helper Functions
Note: When reconciling pending rewards with actual withdrawals, be aware of the 12-decimal difference (10^12 factor) between query results and withdrawal amounts.
Practical Examples
DeFi Yield Aggregator
Validator Commission Manager
Error Handling
Common error scenarios and how to handle them:Gas Optimization Tips
- Batch Operations: Use
withdrawMultipleDelegationRewardsfor multiple validators - Check Before Withdraw: Query rewards first to avoid unnecessary transactions
- Set Withdraw Address Once: Avoid repeated
setWithdrawAddresscalls - Commission Timing: Withdraw validator commission when amounts are substantial
Integration Patterns
Auto-Compounding Strategy
Treasury Management
View the complete distribution precompile source code and ABI here.