Skip to main content

2. Deploy to Testnet

To recap what we've done so far, in Setup:

  • we set up our local environment to write Rust smart contracts
  • installed the soroban-cli
  • configured the soroban-cli to communicate with the Soroban Testnet via RPC
  • and configured an identity to sign transactions

In Hello World we wrote a simple contract, and now we are ready to deploy that contract to Testnet, and interact with it.


To deploy your Hello Soroban contract, run the following command:

soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/hello_soroban.wasm \
--source alice \
--network testnet

This returns the ID of the contract, starting with a C. Let's put it somewhere semi-permanent so we can use it later. Copy that value and put it into a file in the .soroban directory called hello-id. You may need to create the .soroban folder first with mkdir .soroban.

echo "C...[your contract id here]" > .soroban/hello-id


Using the code we wrote in Write a Contract and the resulting .wasm file we built in Build, run the following command to invoke the hello function.


In the background, the CLI is making RPC calls. For information on that checkout out the RPC reference page.

Here we're setting the to argument to RPC. This again makes use of command expansion $(…); see the note about that in the Configure an Identity section of Setup.

soroban contract invoke \
--id $(cat .soroban/hello-id) \
--source alice \
--network testnet \
-- \
hello \
--to RPC

The following output should appear.

["Hello", "RPC"]

The -- double-dash is required!

This is a general CLI pattern used by other commands like cargo run. Everything after the --, sometimes called slop, is passed to a child process. In this case, soroban contract invoke builds an implicit CLI on-the-fly for the hello method in your contract. It can do this because Soroban SDK embeds your contract's schema / interface types right in the .wasm file that gets deployed on-chain. You can also try:

soroban contract invoke ... -- --help


soroban contract invoke ... -- hello --help


In this lesson, we learned how to:

  • deploy a contract to Testnet
  • interact with a deployed contract

You shouldn't have any changes to commit to git, because we didn't change any code in this lesson!

Next we'll add a new contract to this project, reorganizing the project as a multi-contract project using Cargo Workspaces. The new contract will show off a little bit of Soroban's storage capabilities.