Skip to main content

4. Deploy Incrementor

Two-step deployment

It's worth knowing that deploy is actually a two-step process.

  1. Upload the contract bytes to the network. Soroban currently refers to this as installing the contract—from the perspective of the blockchain itself, this is a reasonable metaphor. This uploads the bytes of the contract to the network, indexing it by its hash. This contract code can now be referenced by multiple contracts, which means they would have the exact same behavior but separate storage state.

  2. Instantiate the contract. This actually creates what you probably think of as a Smart Contract. It makes a new contract ID, and associates it with the contract bytes that were uploaded in the previous step.

You can run these two steps separately. Let's try it with the Incrementor contract:

soroban contract install \
--network testnet \
--source alice \
--wasm target/wasm32-unknown-unknown/release/incrementor.wasm

This returns the hash of the Wasm bytes. Now you can use --wasm-hash with deploy rather than --wasm. Let's also automatically pipe the returned contract ID into a file in the .soroban directory, so that when you search your command history and reuse the deploy command in the future, you don't forget that step (you might want to go back and do something similar with the Hello World deploy, too):

soroban contract deploy \
--wasm-hash [paste the output from the last command] \
--source alice \
--network testnet \
> .soroban/incrementor-id

You can check that it saved the contract ID correctly:

cat .soroban/incrementor-id

Now you can interact with it over RPC like you did with the Hello World contract:

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

You should see the following output:


Run it a few more times to watch the count change.

Run your own network/node

Sometimes you'll need to run your own node:

  • Production apps! Stellar maintains public test RPC nodes for Testnet and Futurenet, but not for Mainnet. Instead, you will need to run your own node, and point your app at that. If you want to use a software-as-a-service platform for this, various providers are available.
  • When you need a network that differs from the version deployed to Testnet.

The Soroban team maintains Docker containers that makes this as straightforward as possible. See the RPC reference for details.

Up next, we'll use the deployed contracts to build a simple web app.