Skip to main content

Build and Run

Build a Contract

To build a Soroban contract to deploy or run with the soroban-cli, use the cargo build command.

cargo build --target wasm32-unknown-unknown --release

A .wasm file will be outputted in the target directory. The .wasm file is the built contract.

target/wasm32-unknown-unknown/release/[project_name].wasm

Run a Contract

If you have the soroban-cli installed, you can invoke contract functions that have been built.

Using the code we wrote in Write a Contract and the resulting .wasm file we built in Build and Run run the following command to invoke the hello function with a single argument friend.

soroban-cli invoke \
--wasm target/wasm32-unknown-unknown/release/first_project.wasm \
--id 1 \
--fn hello \
--arg friend

The following output should appear.

["Hello","friend"]