/patine

Primary LanguageRust

Patine

Write EVM contract using Rust.

Features and TODO

  • Generate EVM bytecode from Rust code.

  • Contract compostion.

  • Call contract in contract.

  • Follow the soldity ABI and call convention.

  • Generate ABI.

  • Generate client SDK.

  • Core library.

    • FFI
    • Warpped Function
    • UInt
    • BytesN
    • SInt
    • Address
    • Add AsRef and AsMut
    • Add From
    • Add TryFrom
    • Add "UnsafeFrom" and UnsafeInto
    • Memory
  • Std

    • Selector
    • ABI
    • Contract
    • Context
      • Msg
      • Transaction
      • Block
  • Macros

    • Contract
    • uint!
    • Event
    • AbiEncode, AbiDecode
    • Function Call

Perquisites

Install cargo-evm by cargo binstall.

cargo binstall cargo-evm

Create Contract Project

Create project using the following command:

cargo evm new "<your-project-name>"

Write Contract

Please add your contract file under src. We use simple store contract as example.

use patine::{storage::{Value, Storage}, U256};

#[contract]
pub struct Contract {
    value: Value<U256, Storage>,
}

#[contract]
impl Contract {
    #[expose]
    pub fn store(&mut self, value: U256) {
        self.value.set(value)
    }

    #[expose]
    pub fn load() -> U256 {
        self.value.get()
    }
}