#ethereum #up #back-end #develop #kv #token #sew

nightly sewup

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

25 releases

0.1.14 Feb 27, 2022
0.1.10 Dec 9, 2021
0.1.9 Nov 23, 2021
0.0.6 Jul 23, 2021

#20 in #develop

Apache-2.0 and maybe AGPL-3.0

175KB
4.5K SLoC

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. Sewup is a blockchain Rust contract framwork base on ethereum webassembly, and suitable for any ethereum wabassembly blockchain. If you have question about Rust contract framework, and about the different between these, you can check out this wiki page of contract framework. 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 withb bucket partition
  • rdb - for writing contract as relational database
  • token - for writing ERC-20, ERC-721, ERC-1155 tokens
  • single-bucket(working in process) - for the storage without bucket partition

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 from the doc of ewasm_main! and the wiki page of Deploy Guide.

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!. Besides, it easy to know the exactly detail of storage with ewasm_storage_debug!. And all these debug method should run test of 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.

Dependencies

~16MB
~259K SLoC