A library to help you sew up your Ethereum project with Rust and just like develop in a common backend

Related tags

Cryptography SewUp
Overview

SewUp

GitHub Workflow Status Generic badge Generic badge Generic badge Generic badge Generic badge

Secondstate EWasm Utility Program, a library helps you sew up your Ethereum project with Rust and just like development in a common backend. There is an issue on building document on Doc.rs, please kindly use the document of master instead. Furthermore, there is also wiki site helps you work with sewup, once you got problems or confusing you can learn more on the wiki.

Slides & Demo

Date Event Version Slide Video Material
2021/12/03 ParaState Hackathon IV 0.1.9 hackthon4 todo app
2021/11/12 ParaState Hackathon III 0.1.7 hackthon3 utility token
2021/11/3 ParaState Hackathon II 0.1.6 hackthon2 record2 material, hangman
2021/10/30 COSCon'21 0.1.4 coscon21
2021/10/26 ParaState Hackathon 0.1.4 hackthon1 record1 material
2021/09/07 Version 0.1 release 0.1.0 Hello, KV, RDB, ERC-20, ERC-721, ERC-1155
2021/06/19 Rust meetup (Beijing) 0.0.1 prerelease

Usage

Add sewup with the features and the sewup-derive into Cargo.toml, and setup other sections as following, then you are ready to build contract with sewup.

Features list (should select none or one of following)

  • kv - for writing contract as key value database
  • rdb - for writing contract as relational database
  • token - for writing ERC-20, ERC-721, ERC-1155 tokens

Beside, we suggest you using anyhow to handle your result and error, but not limited to, if you want to use other error crate please checkout #[ewasm_main(rusty)] and learn more. If you want to write a contract return different type of data base on different handlers, please checkout #[ewasm_main(auto)] and EwasmAny or the example of rdb feature to learn how to write a flexible smart contract with ewasm.

Develop

It is easy to setup your sewup project with cargo-sewup with following commands.

  • cargo install cargo-sewup
  • cargo sewup init You can use -m <rusty|auto> option to initialize different type of sewup project, and you can learn more about the project configure with the Deploy Guide wiki page.

Interact

There are so many clients can interact with contract.

For ERC tokens, we provide web3js examples in wiki page. The example of clients interacting with contract with kv or rdb features. You can in the example projects for kv and rdb, then Cargo run to interact with the contract after modified the contract address.

Testing

Run cargo build --release --target=wasm32-unknown-unknown, then the contract will build in target/wasm32-unknown-unknown/release/*.wasm Besides, you can run deploy the ewasm contract on WasmEdge and run tests on it with cargo test, furthermore the constructor will also run when the contract deploying on WasmEdge. If you want to learn more details about the testing flow, please check out Test the contract section of develop guide wiki page.

Debugging

Furthermore, you can debug your ewasm contract with debug macro sewup::ewasm_dbg!, and run the contract with message output by cargo test -- --nocapture. To learn more about the usage, you check out the examples in the example folder.

Deployment

Once you want to deploy your contract to any network which support Ewasm by sweup command line tool, please read the Deploy Guide wiki page.

SewUp Development

There are two projects and several examples in the workspace, the contract project should build with target wasm32-unknown-unknown and the flag -C link-arg=--export-table. You can run cargo test in each example folder to check on the test your modification.

It is easy to participate with help want issues and the good first issues. Less but not least, please feel free to open any issue on this project.

Comments
  • `cargo test` failed

    `cargo test` failed

    When I use cargo test to build the hello-contracts, it failed.

    Error messages:

       Compiling num-traits v0.2.14
       Compiling libloading v0.5.2
       Compiling hashbrown v0.8.2
       Compiling ssvm-evmc-client v6.3.1-rc4
    error: failed to run custom build command for `ssvm-evmc-client v6.3.1-rc4`
    
    Caused by:
      process didn't exit successfully: `/home/azureuser/SewUp/examples/hello-contract/target/debug/build/ssvm-evmc-client-e7754bbb80b19255/build-script-build` (exit status: 101)
      --- stdout
      CMAKE_TOOLCHAIN_FILE_x86_64-unknown-linux-gnu = None
      CMAKE_TOOLCHAIN_FILE_x86_64_unknown_linux_gnu = None
      HOST_CMAKE_TOOLCHAIN_FILE = None
      CMAKE_TOOLCHAIN_FILE = None
      CMAKE_GENERATOR_x86_64-unknown-linux-gnu = None
      CMAKE_GENERATOR_x86_64_unknown_linux_gnu = None
      HOST_CMAKE_GENERATOR = None
      CMAKE_GENERATOR = None
      CMAKE_PREFIX_PATH_x86_64-unknown-linux-gnu = None
      CMAKE_PREFIX_PATH_x86_64_unknown_linux_gnu = None
      HOST_CMAKE_PREFIX_PATH = None
      CMAKE_PREFIX_PATH = None
      CMAKE_x86_64-unknown-linux-gnu = None
      CMAKE_x86_64_unknown_linux_gnu = None
      HOST_CMAKE = None
      CMAKE = None
      running: "cmake" "/home/azureuser/.cargo/registry/src/github.com-1ecc6299db9ec823/ssvm-evmc-client-6.3.1-rc4/target/evmc-6.3.1-rc4-crates" "-DCMAKE_INSTALL_PREFIX=/home/azureuser/SewUp/examples/hello-contract/target/debug/build/ssvm-evmc-client-004d03299e68aa05/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_C_COMPILER=/usr/bin/cc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_COMPILER=/usr/bin/c++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_ASM_COMPILER=/usr/bin/cc" "-DCMAKE_BUILD_TYPE=Debug"
    
      --- stderr
      thread 'main' panicked at '
      failed to execute command: No such file or directory (os error 2)
      is `cmake` not installed?
    
      build script failed, must exit now', /home/azureuser/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.46/src/lib.rs:974:5
      note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    warning: build failed, waiting for other jobs to finish...
    error: build failed
    
    opened by rustcryptogo 2
  • Handle `0x` prefix `str` for `Address`

    Handle `0x` prefix `str` for `Address`

    Currently, Address type can use from_str to build the instance, for example.

    let charman_address = Address::from_str("8663DBF0cC68AaF37fC8BA262F2df4c666a41993")?;
    

    The API just fit and easily for the developer using web3.js before.

    And there is a similar another API in Rust crate web3.

    let charman_address = Address::from_str("0x8663DBF0cC68AaF37fC8BA262F2df4c666a41993")?;
    

    So it is good to make this the 0x prefix input also work in sewup, such that developer can use this much easier.

    enhancement good first issue Hacktoberfest 
    opened by yanganto 2
  • The ERC 20 examples doesn't support `0x`

    The ERC 20 examples doesn't support `0x`

    I want to deploy the erc20 token smart contracts via SewUp with my own address replacing the address in erc20-examples. I copied my 0xxxxxxxxxxxxxx address copied from MetaMask, then cargo sewup failed. So I tried to delete 0x, then cargo sewup successes.

    opened by alabulei1 1
  • Let developer easier to provide the abi json

    Let developer easier to provide the abi json

    The abi json is provided by written json string of full object, however, it may be a good way that developer can provide less information and the field not provided will using the default value, such that the framework will be much user/developer friendly.

    https://github.com/second-state/SewUp/blob/main/sewup/src/token/erc20.rs#L27-L37

    So the issue can be split into the following issues.

    • [x] #282
    • [x] #283
    • [x] #285
    good first issue utils Hacktoberfest 
    opened by yanganto 1
  • Fixed ECMC version to 6.x between rust-ssvm and ecmc binding

    Fixed ECMC version to 6.x between rust-ssvm and ecmc binding

    Verify done in all example/*. Prefer merge option use rebase and merge.

    By the way, if error "Blocking waiting for file lock on the registry index” after building parity from source happened, need

    rm -rf ~/.cargo/registry/index/*.
    

    Ref to stackoverflow

    opened by CaptainVincent 1
  • Default handle when function not exsist

    Default handle when function not exsist

    There should be a good handle when calling a non-exist function in the contract.

    https://github.com/second-state/SewUp/blob/main/examples/hello-contract/src/lib.rs#L16

    help wanted utils 
    opened by yanganto 1
  • Allow user to use the function named `main` for #[ewasm_main]

    Allow user to use the function named `main` for #[ewasm_main]

    #[ewasm_main] is a macro to wrap a function to with main function for ewasm. Currently, the function wrappered is not allow to be name as main.

    For a better UX, it is good to rename the function when its name is main, and not panic.

    Please help with this issue.

    Relate PR #35 https://github.com/second-state/SewUp/pull/35/files#diff-6f891a9986798db9fa65d7dd779c98c44afa864739fdd39a556eafdcdb75a943R19 https://github.com/second-state/SewUp/blob/main/sewup-derive/src/lib.rs#L19

    help wanted utils 
    opened by yanganto 1
  • Implement Bucket for kv feature

    Implement Bucket for kv feature

    • [x] new()
    • [x] contains(&self, _key: Any)
    • [x] get(&self, _key: Any)
    • [x] set(&self, _key: Any, _value: Any)
    • [x] remove(&self, _key: Any)
    • [x] iter(&self)
    • [x] iter_range(&self, a: Any, b: Any)
    • [ ] iter_prefix(&self, a: Any)
    • [ ] watch(&self, key: Any)
    • [x] prev_key(&self, key: Any)
    • [x] next_key(&self, key: Any)
    • [x] pop(&self, key: Any)
    • [x] pop_back(&self)
    • [x] pop_front(&self)
    • [x] len(&self)
    • [x] is_empty(&self)
    KV 
    opened by yanganto 1
  • Default message when contract execution fail

    Default message when contract execution fail

    Return the default message when execution is not expected

    #[ewasm_main(default="Something does not works")]
    fn main() -> anyhow::Result<()> { .. } 
    

    or

    #[ewasm_main(auto, default="Something does not works")]
    fn main() -> anyhow::Result<()> { .. } 
    
    opened by yanganto 0
  • Update  svm-evmc-client and rust-ssvm

    Update svm-evmc-client and rust-ssvm

    The dependency of ssvm-evmc-client should be refactored, if evmc-sys can be reexported like evmc-client, or evmc-sys can be reexport in evmc-client. https://github.com/second-state/rust-ssvm/blob/v0.1.0-rc2-crates/src/lib.rs#L17

    gitcoin 
    opened by yanganto 0
  • Cross platform build

    Cross platform build

    Currently, SewUp use nix solution can work well on Linux and macOS.

    The versions greater than 0.8.2 ofWasmEdge can be built cross-platform, and SewUp use WasmEdge to run test.

    Once the Wasmedge upgrated (#24 ), the CI can work on building sewup on windows.

    Besides, the cargo.toml should be set with clear supported targets.

    [package.metadata.docs.rs]
    targets = ["x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc", "wasm32-unknown-unknown" ... ]
    
    CI dependency 
    opened by yanganto 0
Releases(v0.1.14)
  • v0.1.14(Feb 27, 2022)

    • remove the dependency of regex
    • provide only_by option in ewasm_fn
    • refactor address redundant type
    • update the print style of debugging
    • provide storage debugger for runtime in test
    Source code(tar.gz)
    Source code(zip)
  • v0.1.13(Jan 31, 2022)

    • Implement prev_key, next_key for KV feature
    • Use sewup address type as parameter in Token feature
    • Check cargo toml setting of sewup project when building ewasm contract
    • Validation for abi json input in Token feature
    • One or none to many relation in RDB feature
    Source code(tar.gz)
    Source code(zip)
  • v0.1.11(Jan 1, 2022)

    • cargo sewup version checking and warning
    • save metadata when building contract
    • allow mint with 0x address
    • pop related function for kv feature
    Source code(tar.gz)
    Source code(zip)
  • v0.1.10(Dec 9, 2021)

    • Provide EwasmAny for Rusty mode
    • Allow any constructor name
    • Implement convert for signed int and raw
    • tests-build on multiple features
    • Update to 2021 edition
    Source code(tar.gz)
    Source code(zip)
  • v0.1.9(Nov 23, 2021)

    • Provide Default, Debug trait for Address type
    • Provide same serial format between different target
    • Provide id information when filtering table and get records (RDB feature)
    Source code(tar.gz)
    Source code(zip)
  • v0.1.7(Nov 4, 2021)

  • v0.1.5(Oct 15, 2021)

    • Try to decode error message when test fail
    • Show the specific caller when test fail
    • Handle 0x prefix address in Address
    • Handle 0x prefix address for test runtime
    • Fix doc with wasm target
    • Implement Key, Value trait for all unsigned integers
    • Implement Key, Value traits for String and SizedString

    Special thanks: @carlosfrodrigues

    Source code(tar.gz)
    Source code(zip)
  • v0.1.4(Oct 8, 2021)

    • Provide Address type
    • Implement Key, Value trait for Address type
    • Provide ballot-contract for voting example
    • Implement ewasm_call_only_by! macro for access control on contract handler
    • Implement sewup::utils::caller to get the Address of caller
    Source code(tar.gz)
    Source code(zip)
  • v0.1.3(Oct 4, 2021)

  • v0.1.2(Sep 22, 2021)

  • v0.1.1(Sep 14, 2021)

  • v0.1.0(Sep 3, 2021)

  • v0.0.11(Aug 27, 2021)

    • setup caller for test environment with by, ex: ewasm_assert_eq!( handler by "0xaddre" )
    • generate input data binary, ewasm_input!( input_instance for handler)
    Source code(tar.gz)
    Source code(zip)
  • v0.0.10(Aug 20, 2021)

  • v0.0.9(Aug 14, 2021)

  • v0.0.8(Aug 5, 2021)

    Contract deployment tool and flow

    • Add cargo-sewup
      • deploy contract
      • inspect deploy file
    • Add constructor function
      • implment #[ewasm-constructor]
      • run constructor in test case
    Source code(tar.gz)
    Source code(zip)
  • v0.0.7(Aug 5, 2021)

  • v0.0.6(Jul 23, 2021)

    Query on records for RDB feature

    • query filter function for rdb feature
    • query selector function for rdb feature
    • refactor Table derive
    • tables as modules for rdb feature
    • EwasmAny as a generic return type for ewasm contract
    Source code(tar.gz)
    Source code(zip)
  • v0.0.5(Jul 16, 2021)

    Better test error message

    • add macro ewasm_dbg!
    • refactor macros for betterr debug message
    • provide runtime log save feature
    • provide multiple user and balace feature for test runtime
    Source code(tar.gz)
    Source code(zip)
  • v0.0.4(Jul 13, 2021)

    Building ewasm contract like using RDB

    • storage data into the table as a fixed-sized record
    • basic create, read, update, delete handers to manipulate the records in the table
    Source code(tar.gz)
    Source code(zip)
  • v0.0.3(Jul 13, 2021)

    A better testing environment with following macros, such that user can write and test as the same experience of other Rust project

    • ewasm_assert_eq
    • ewasm_assert_ok
    • ewasm_err_output
    • ewasm_rusty_assert_ok
    • ewasm_rusty_err_output
    • ewasm_auto_assert_eq
    • ewasm_output_from
    • ewasm_test
    Source code(tar.gz)
    Source code(zip)
  • v0.0.2(Jul 13, 2021)

  • v0.0.1(Jul 13, 2021)

    The minimum implementation with important utils.

    • basic contract utils
    • basic kv utils for contract
    • document for the contract utils
    • examples for kv contract

    It's not ready for everyone. It's a developer preview version and in very active development. API may change frequently.

    Source code(tar.gz)
    Source code(zip)
Owner
Second State
Fast, safe, portable & serverless. Deploy Rust functions in edge computing, Jamstack, SaaS and service mesh applications.
Second State
Parser and test runner for testing compatable common Ethereum full node tests against Polygon Zero's EVM.

EVM Test Parses and runs compatible common Ethereum tests from ethereum/tests against Polygon Zero's EVM. Note: This repo is currently very early in d

Mir Protocol 3 Nov 4, 2022
Substreams development kit for Ethereum chains, contains Firehose Block model and helpers as well as utilities for Ethereum ABI encoding/decoding.

Substreams Ethereum Substreams development kit for Ethereum chains, contains Rust Firehose Block model and helpers as well as utilities for Ethereum A

StreamingFast 15 Oct 25, 2022
Rust project for working with ETH - Ethereum transactions with Rust on Ganache and also deploy smart contracts :)

Just a test project to work with Ethereum but using Rust. I'm using plain Rust here, not Foundry. In future we will use Foundry. Hope you're already f

Akhil Sharma 2 Dec 20, 2022
The fast, light, and robust client for Ethereum-like networks.

The Fastest and most Advanced Ethereum Client. » Download the latest release « Table of Contents Description Technical Overview Building 3.1 Building

OpenEthereum 6.7k Dec 24, 2022
A collection of lints to catch common mistakes and improve your Cairo code.

cairo-lint A collection of lints to catch common mistakes and improve your Cairo code. Usage cairo-lint can either be used as a library or as a standa

Keep Starknet Strange 19 Oct 18, 2024
Terra Trophies is a copy of Ethereum's POAP project for Terra

Terra Trophies Terra Trophies is a copy of Ethereum's POAP project for Terra. It allows anyone to create digital badges for participants of events, or

larry.{ust,sol,thor} 18 Dec 7, 2022
Project Masterpass is a deterministic databaseless key management algorithm, aimed to help those who cannot protect their encryption keys in storage

Project Masterpass (working title) Attention! This project is still under heavy development, and SHOULD NOT be used in practice, as the algorithms cou

Gyorgy Wang 2 Sep 11, 2022
Bitcoin Push Notification Service (BPNS) allows you to receive notifications of Bitcoin transactions of your non-custodial wallets on a provider of your choice, all while respecting your privacy

Bitcoin Push Notification Service (BPNS) Description Bitcoin Push Notification Service (BPNS) allows you to receive notifications of Bitcoin transacti

BPNS 1 May 2, 2022
Common cryptographic library used in software at Mysten Labs.

[fastcrypto] fastcrypto is a common cryptography library used in software at Mysten Labs. It is published as an independent crate to encourage reusabi

Mysten Labs 85 Dec 20, 2022
Vanitygen-bip39 - Generate vanity / gas efficient Ethereum addresses for your hdwallet (bip39 12 or 24 words)

vanitygen-bip39 Generate Ethereum gas efficient addresses with leading zeros https://medium.com/coinmonks/on-efficient-ethereum-addresses-3fef0596e263

iam4x 9 Jul 2, 2022
Ethereum JSON-RPC multi-transport client. Rust implementation of web3 library

Ethereum JSON-RPC multi-transport client. Rust implementation of web3 library. ENS address: rust-web3.eth

Tomasz Drwięga 1.2k Jan 8, 2023
Common protocol for generating ZK proofs for blocks on different blockchains.

Proof Protocol Decoder A flexible protocol that clients (eg. full nodes) can use to easily generate block proofs for different chains. Specification I

Polygon Zero 3 Oct 5, 2023
Bellman zkSNARK library for community with Ethereum's BN256 support

bellman "Community edition" Originally developed for ZCash, with extensions from us to make it a little more pleasant. Uses our "community edition" pa

Matter Labs 113 Dec 29, 2022
Complete Ethereum and Celo wallet implementation and utilities in Rust

ethers.rs Complete Ethereum and Celo wallet implementation and utilities in Rust Documentation Extensive documentation and examples are available here

Georgios Konstantopoulos 1.5k Jan 8, 2023
Terabethia - A Bridge and Messaging Protocol between Ethereum and the Internet Computer.

Terabethia - A Bridge Between Ethereum & the Internet Computer Terabethia is a bridge between Ethereum & the Internet Computer that contracts in both

Psychedelic 36 Dec 26, 2022
Rust client to Opensea's APIs and Ethereum smart contracts

opensea.rs Rust bindings & CLI to the Opensea API and Contracts CLI Usage Run cargo r -- --help to get the top level help menu: opensea-cli 0.1.0 Choo

Georgios Konstantopoulos 226 Dec 27, 2022
Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.

foundry Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust. Foundry consists of: Forge: Ethe

Georgios Konstantopoulos 5.1k Jan 9, 2023
Rust client to Seaport's APIs and Ethereum smart contracts(WIP)

Seaport-rs WIP - WORK IN PROGRESS. REFER TO https://github.com/Alcibiades-Capital/quay FOR PRODUCTION READY CODE I'm new to Rust and seek to be legend

Perelyn 21 Nov 29, 2022
The fast, light, and robust client for the Ethereum mainnet.

OpenEthereum Fast and feature-rich multi-network Ethereum client. » Download the latest release « Table of Contents Description Technical Overview Bui

OpenEthereum 1.6k Dec 28, 2022