/near-smart-contract-rust-template

Project structure for writing smart contracts in Rust for NEAR Protocol

Primary LanguageRustGNU General Public License v3.0GPL-3.0

NEAR Smart Contract Rust Template

Project structure for writing smart contracts for NEAR in Rust.

Required Software

  • Rust ^1.60 + Cargo
    • With the WASM target installed: rustup target add wasm32-unknown-unknown
    • cargo-make: cargo install cargo-make
  • 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.
  • NEAR CLI ^3.4.1: npm install -g near-cli

Usage

Scripts

cargo make clean

Removes the target and neardev directories.

cargo make test

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.)

cargo make build

Compiles the smart contract to a WebAssembly binary. The binary path is ./target/wasm32-unknown-unknown/release/<package>.wasm.

cargo make call <method> <method-args> <...arguments>

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.

cargo make call-self <method> <method-args> <...arguments>

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.

cargo make view <method> <method-args> <...arguments>

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.

cargo make deploy <account-id>

Deploys the most recently built WASM binary to <account-id> on the network specified by NEAR_ENV, and calls the new function with arguments generated by args.sh.

cargo make dev-deploy [--force]

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.

Authors