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
Find the Solidity interface in the Paxeer Network/extensions repo.
ABI
Find the ABI in the Paxeer Network/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. -
undelegateundelegatedefines a method for performing an undelegation from a delegate and a validator. -
redelegateRedelegate defines a method for performing a redelegation of coins from a delegator and source validator to a destination validator -
cancelUnbondingDelegationcancelUnbondingDelegationallows delegators to cancel the unbondingDelegation entry and to delegate back to a previous validator.
Queries
-
delegationget the given amount of the bond denomination to a validator. -
unbondingDelegationunbondingDelegationreturns the unbonding delegation -
validatorvalidatorqueries validator info for given validator address -
validatorsvalidatorsqueries all validators that match the given status -
redelegationredelegationqueries all redelegations from a source to a destination validator for a given delegator -
redelegationsredelegationsqueries all redelgations based on the specified criteria: for a given delegator and/or origin validator address and/or destination validator address 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 allx/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
ThestakeTokens 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
TheunstakeTokens 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 theredelegateTokens 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 thecancelUnbondingDelegation 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 thesegetDelegation and getUnbondingDelegation
functions that return the information for the specified validator address.