#smart-contracts #contract #testing #command-line-tool #cargo-toml #networking #casper-labs

yanked cargo-casperlabs

Command line tool for creating a Wasm smart contract and tests for use on the CasperLabs network

0.9.1 Jul 31, 2020
0.8.1 Jul 2, 2020
0.7.0 Mar 31, 2020

#19 in #casper-labs

31 downloads per month

Custom license

380KB
583 lines

cargo casperlabs

LOGO

Build Status Crates.io Documentation License

A command line tool for creating a Wasm smart contract and tests for use on the CasperLabs network.

Installation

cargo casperlabs is a Cargo subcommand which can be installed via cargo install:

cargo install cargo-casperlabs

To install from the latest dev branch:

git clone https://github.com/CasperLabs/CasperLabs
cd CasperLabs/execution-engine/cargo-casperlabs
cargo install cargo-casperlabs --path=.

Usage

To create a folder "my_project" containing an example contract and a separate test crate for the contract:

cargo casperlabs my_project

This creates the following files:

my_project/
├── contract
│   ├── .cargo
│   │   └── config
│   ├── Cargo.toml
│   ├── rust-toolchain
│   └── src
│       └── main.rs
├── tests
│   ├── build.rs
│   ├── Cargo.toml
│   ├── rust-toolchain
│   ├── src
│   │   └── integration_tests.rs
│   └── wasm
│       ├── mint_install.wasm
│       ├── pos_install.wasm
│       ├── standard_payment_install.wasm
│       └── standard_payment.wasm
└── .travis.yml

Building the contract

To build the contract, the correct version of Rust must be installed along with the Wasm target:

cd my_project/contract
rustup install $(cat rust-toolchain)
rustup target add --toolchain=$(cat rust-toolchain) wasm32-unknown-unknown

The contract can now be built using:

cargo build --release

and will be built to my_project/contract/target/wasm32-unknown-unknown/release/contract.wasm.

Testing the contract

Running the test will automatically build the contract in release mode, copy it to the "tests/wasm" folder, then build and run the test:

cd my_project/tests
cargo test

License

Licensed under the CasperLabs Open Source License (COSL).

Dependencies

~3MB
~41K SLoC