Build & deploy
Compile to wasm, deploy to a named account you control, then call it. A transaction call changes state; a read-only call reads for free.
Beginner3 min read3-question check
The build-and-ship loop maps almost one-to-one to Foundry, with two NEAR-isms: you compile to wasm, and you deploy to a named account you already control rather than to a fresh address.
# build
forge build
# deploy (creates a new address)
forge create src/Counter.sol:Counter \
--rpc-url $RPC --private-key $PK
# change call (a transaction, signed)
cast send $ADDR "increment()" --private-key $PK
# read call (free, no signature)
cast call $ADDR "count()(uint256)"# build the contract to wasm
# (output: target/near/<crate_name>.wasm — here the crate is "counter")
cargo near build
# deploy the wasm to an account you control
near contract deploy myapp.testnet \
use-file ./target/near/counter.wasm \
without-init-call \
network-config testnet sign-with-keychain send
# change call (a transaction, signed & paid by you)
near contract call-function as-transaction myapp.testnet increment \
json-args '{}' prepaid-gas '30 Tgas' attached-deposit '0 NEAR' \
sign-as you.testnet network-config testnet sign-with-keychain send
# view call (read-only, free, no signature)
near contract call-function as-read-only myapp.testnet get_count \
json-args '{}' network-config testnet nowforge build ↔ cargo near build, which writes target/near/<crate_name>.wasm. forge create ↔ near contract deploy — but the target is an existing account you own, not a freshly minted address. Use with-init-call new json-args ... instead of without-init-call to deploy and run your #[init] in one go.
cast send (state-changing, signed) ↔ call-function as-transaction; cast call (read-only, free) ↔ call-function as-read-only. The change-vs-view split is explicit in the command you run.
The current near CLI is near-cli-rs, and the commands above are its native form. It is interactive too — run near with no arguments and it walks you through account, network, and signing, then prints the full command for reuse in CI.
Older tutorials use the legacy JS near-cli syntax — near deploy <acct> <wasm>, near call <acct> <method> --accountId you, near view <acct> <method>. near-cli-rs still accepts those as best-effort shortcuts and translates them to the native form, but new scripts should use the native commands.
Check yourself
3 questions · progress saved in this browser