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 stellar-cli
  • configured the stellar-cli to communicate with the Stellar Testnet via RPC
  • and configured an identity to sign transactions

In Hello World we created a hello-world project, and learned how to test and build the HelloWorld contract. Now we are ready to deploy that contract to Testnet, and interact with it.

Deploy

To deploy your HelloWorld contract, run the following command:

stellar contract deploy \
--wasm target/wasm32-unknown-unknown/release/hello_world.wasm \
--source alice \
--network testnet

This returns the contract's id, starting with a C. In this example, we're going to use CACDYF3CYMJEJTIVFESQYZTN67GO2R5D5IUABTCUG3HXQSRXCSOROBAN, so replace it with your actual contract id.

Interact

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.

info

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

stellar contract invoke \
--id CACDYF3CYMJEJTIVFESQYZTN67GO2R5D5IUABTCUG3HXQSRXCSOROBAN \
--source alice \
--network testnet \
-- \
hello \
--to RPC

The following output should appear.

["Hello", "RPC"]
info

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, stellar 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:

stellar contract invoke ... -- --help

and

stellar contract invoke ... -- hello --help

Summary

In this lesson, we learned how to:

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

Next we'll add a new contract to this project, and see how our workspace can accommodate a multi-contract project. The new contract will show off a little bit of Soroban's storage capabilities.