Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

A Technology Preview of using Rust Smart Contracts running in a Webassembly Chaincode for Hyperledger Fabric

License

Notifications You must be signed in to change notification settings

hyperledgendary/fabric-contract-api-rust

Repository files navigation

Fabric Rust Contract-API

"The Fabric Contract API in rust, with Wasm as the compilation target."

A SmartContract is single crate, containing one or more contract sructs, compiled to a Wasm library. In this repo the basic_contract_rs is an example. This is a simple asset based contract based on the standard vs code extension examples.

End-to-End Getting Started Guide

Check the API Documentation for fabric_contract

Full Documentation

Technology Preview

NOTE this is a technology preview, rather than production ready. Released for feedback and community experimentation.

Tl;Dr; docs

To write and deploy a Smart Contract

At a very highlevel the steps are

  1. As the crates are not published yet, clone this entire cargo workspace to build both the fabric_contract and your own crates
  2. Write the Smart Contract in rust, see basic_contract_rs for an example
  3. Compile this targetting wasm. cargo build --target wasm32-unknown-unknown
  4. Take the resulting Wasm binary and use the https://github.com/hyperledgendary/fabric-chaincode-wasm project to encapsualte this Wasm file in the 'Wasm Chaincode Runtime'
  5. Once deployed this you interact with this like another contract

For all the steps please follow the Getting Started Guide

Summary of how to build for Wasm

To build a Wasm binary you will need to have rust installed (stable branch is good, nightly is not required). You will need to add the wasm target. (rustup target add wasm32-unknown-unknown if you don't have the Wasm toolchain. Note that wasm-pack is not required here as there is no JavaScript host)

cargo build --target wasm32-unknown-unknown

File will be in target/wasm32-unknown-unknown/debug/basic_contract_rs.wasm

To build documentation

just docs

There is also a justfile for quick command running.