Compile a Rust smart contract module#
This guide will show you how to compile smart contract module written in Rust to a Wasm module.
Make sure to have Rust and Cargo installed and the
target, together with
cargo-concordium and the Rust source code for a smart
contract module, you wish to compile.
For instructions on how to install the developer tools see Install tools for development.
Compiling to Wasm#
In order to build a smart contract, run:
$cargo concordium build
This uses Cargo for building, but runs further optimizations on the result.
For building the schema for a smart contract module, some further preparation is required.
It is also possible to compile using Cargo directly by running:
$cargo build --target=wasm32-unknown-unknown [--release]
Note that even with
--release set, the produced Wasm module includes
cargo concordium build command will produce a smart contract module which can be found
relative to your project root folder in
Alternatively, you can supply the location where to store the smart contract module using
--out option. For example running the following command will output your smart contract module
into the root folder of your project in a file name
$cargo concordium build --out ./my_module.wasm.v1
cargo-concordium produces several smart contract modules with different suffixes. The suffix corresponds
to the smart contract version, i.e.
my_module.wasm/my_module.wasm.v0 for V0 contracts and
for V1 contracts. We recommend using the wasm module with the
(the most-up-to date smart contract version).
my_module.wasm.v1 will be used when deploying a smart contract on-chain.