Project structure for writing smart contracts for NEAR in Rust.
- Rust & Cargo
- With the WASM target installed:
rustup target add wasm32-unknown-unknown
- cargo-make:
cargo install cargo-make
- With the WASM target installed:
- Node.js
- The default initialization arguments script
args.sh
uses the Node.js interpreter, but that can easily be modified if you like. You probably will have Node.js installed anyways since it's required to use the NEAR CLI.
- The default initialization arguments script
- NEAR CLI ^3.4.1:
npm install -g near-cli
Removes the target
and neardev
directories.
Runs unit tests using the default target. (Note: behavior may differ from simply running cargo test
depending on the target specified in .cargo/config.toml
.)
Compiles the smart contract to a WebAssembly binary. The binary path is ./target/wasm32-unknown-unknown/release/<package>.wasm
.
Calls the NEAR CLI:
near call <dev-account> <method> <method-args> <...arguments>
Where <dev-account>
is the account ID of the most recent dev deployment on testnet.
Calls the NEAR CLI:
near call <dev-account> <method> <method-args> <...arguments> --accountId <dev-account>
Where <dev-account>
is the account ID of the most recent dev deployment on testnet.
Calls the NEAR CLI:
near view <dev-account> <method> <method-args> <...arguments>
Where <dev-account>
is the account ID of the most recent dev deployment on testnet.
Cleans up and optimizes the most recently-built WASM binary. The optimized binary path is ./deploy/<name>.wasm
.
Note: In order to optimize the WASM binary, you must have wasm-tools
installed:
cargo install wasm-tools
wasm-tools
is also available on Homebrew:
brew install wasm-tools
Deploys the most recently optimized WASM binary to <account-id>
on the network specified by NEAR_ENV
, and calls the new
function with arguments generated by args.sh
. (Implicitly calls cargo make optimize
beforehand.)
Deploys the most recently built WASM binary to the dev account in neardev/
, or to a new dev account if neardev/
is not found or --force
is set. Calls the new
function with arguments generated by args.sh
.
- Jacob Lindahl jacob.lindahl@near.org @sudo_build