Git Product home page Git Product logo

evme-ics20's Introduction

# Evmos EVM Extensions - Simple Staker Example

This is an example of how to create a smart contract that directly calls
the `Staking` and `Distribution` precompiled contracts on Evmos chain - [Simple Staker](./contracts/SimpleStaker.sol)

This smart contract allows the user to:

- Stake tokens
- Withdraw delegation rewards
- Query current delegations
- Query current delegations rewards

The implementation is straightforward and is a good starting point for anyone who wants to create a smart contract that interacts with the Cosmos SDK.

There are a couple of things to keep in mind when using the precompiled contracts:

## Approvals

Before executing certain transactions on the precompiled contracts,
the user interacting with the smart contract must first approve these.
In case of staking transactions, should specify the amount allowed.
The smart contract developer can choose to either separate
the approval and execution of the precompiled contracts transactions
or to combine them into a single transaction.

We have provided convenient constants - `MSG_DELEGATE`, `MSG_UNDELEGATE`,
`MSG_REDELEGATE`, `MSG_CANCEL_UNDELEGATION` - for easier use.

This is done by calling the `approve` function and will create an authorization grant for the given Cosmos SDK message.

The [Simple Staker](./contracts/SimpleStaker.sol) has the function `approveRequiredMethods()`
to perform the necessary approvals.
It approves the required methods for staking tokens (`MSG_DELEGATE`).

## Allowances

The `Staking` precompile will check if the message sender has enough allowance for the given message type and will
return an error if the transaction exceeds the allowance.

Decreasing the allowance after a successful transaction is not required since we handle it internally.

## Return Structs

The precompiled contracts provide a set of structs that map to Cosmos SDK message returns types.

These structs can be used as return types for smart contract functions or can be used to add further
logic to your smart contracts. Once a transaction is executed, the return values can be used to verify the transaction
was successful or be as inputs for additional logic.

## Failed Transactions

The precompiled contracts provide verbose error messages for failed transactions. If a transaction fails, the state
will not be persisted and the transaction will be reverted.

evme-ics20's People

Contributors

biphan4 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.