Staking
Solidity Interface & ABI
Staking.sol is an interface through which Solidity contracts can interact with Cosmos SDK staking. This is convenient for developers as they don’t need to know the implementation details behind the x/staking module in the Cosmos SDK. Instead, they can interact with staking functions using the Ethereum interface they are familiar with.
Interface Staking.sol
Staking.solFind the Solidity interface in the evmos/extensions repo.
ABI
Find the ABI in the evmos/extensions repo.
Transactions
The Staking solidity interface includes the following transactions
delegatedelegatedefines a method for performing a delegation of coins from a delegator to a validator.function delegate( address delegatorAddress, string memory validatorAddress, uint256 amount ) external returns (bool success);undelegateundelegatedefines a method for performing an undelegation from a delegate and a validator.function undelegate( address delegatorAddress, string memory validatorAddress, uint256 amount ) external returns (int64 completionTime);redelegateRedelegate defines a method for performing a redelegation of coins from a delegator and source validator to a destination validator
function redelegate( address delegatorAddress, string memory validatorSrcAddress, string memory validatorDstAddress, uint256 amount ) external returns (int64 completionTime);cancelUnbondingDelegationcancelUnbondingDelegationallows delegators to cancel the unbondingDelegation entry and to delegate back to a previous validator.function cancelUnbondingDelegation( address delegatorAddress, string memory validatorAddress, uint256 amount, uint256 creationHeight ) external returns (bool success);
Queries
delegationget the given amount of the bond denomination to a validator.
unbondingDelegationunbondingDelegationreturns the unbonding delegationvalidatorvalidatorqueries validator info for given validator addressvalidatorsvalidatorsqueries all validators that match the given statusredelegationredelegationqueries all redelegations from a source to a destination validator for a given delegatorredelegationsredelegationsqueries redelegations of given address for a given delegator in a specified pagination manner
Events
Each of the transactions emits its corresponding event. These are:
DelegateDelegate defines an Event emitted when a given amount of tokens are delegated from the delegator address to the validator address
UnbondUnbond defines an Event emitted when a given amount of tokens are unbonded from the validator address to the delegator address
RedelegateRedelegate defines an Event emitted when a given amount of tokens are redelegated from the source validator address to the destination validator address
CancelUnbondingDelegationCancelUnbondingDelegation defines an Event emitted when a given amount of tokens that are in the process of unbonding from the validator address are bonded again
Interact with the Solidity Interface
Below are some examples of how to interact with this Solidity interface from your smart contracts.
Make sure to import the precompiled interface, e.g.:
Grant approval for the desired messages
See below a function that grants approval to the smart contract to send all x/staking module messages on behalf of the sender account. In this case, the allowance amount is the maximum amount possible. You can tweak this function to approve only the desired messages and amounts.
Delegate to a validator
The stakeTokens function allows the transaction sender to delegate the specified amount to his/her favorite validator. Keep in mind that, for this transaction to be successful, the user should have approved the MSG_DELEGATE previously (see the approveAllStakingMethodsWithMaxAmount defined in the code snippet above as an example). This function returns the completion time of the staking transaction and emits a Delegate event.
Undelegate from a validator
The unstakeTokens function allows a user to unstake a given amount of tokens. It returns the completion time of the unstaking transaction and emits an Undelegate event.
Redelegate to another validator
With the redelegateTokens function, a user can redelegate a given amount of tokens. It returns the completion time of the redelegate transaction and emits a Redelegate event.
Cancel unbonding from a validator
With the cancelUnbondingDelegation function, a user can cancel an unbonding delegation. This function returns the completion time of the unbonding delegation cancellation transaction and emits a CancelUnbondingDelegation event.
Queries
Similarly to transactions, smart contracts can use query methods. To use these methods, there is no need for authorization, as these are read-only methods. Examples of this are these getDelegation and getUnbondingDelegation functions that return the information for the specified validator address.
Last updated

