Smart Contract Cheat Sheet
Collection of code snippets and information bits on smart contract development for Dusk.
Common Data Structures
Because we program for WASM in no-std some data structures are not available. Here is a list of common alternatives:
Example | Explanation |
---|---|
BTreeMap | Alternative to HashMap in a no-std env |
BTreeSet | Alternative to HashSet in a no-std env |
Common host functions
Function | Explanation |
---|---|
rusk_abi::emit(“EVENT_NAME”, data) | Emit a contract event |
Common Dependencies
- execution-core
- rusk_abi
No-std Crates
- core
- alloc
The alloc crate needs to explicitly be imported in order to use heap-allocated values in a #![no-std] environment. More information on the alloc crate can be found here.
Simple Contract Template
Example Makefile to compile to WASM
More references
The Rust Language Cheat Sheet is another great cheat sheet that can be used as a reference for Rust code.
Note: Not all examples apply due to our no-std constraints.