Skip to main content

4. Deploy the Increment Contract

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 Increment contract:

stellar contract install \
--network testnet \
--source alice \
--wasm target/wasm32-unknown-unknown/release/soroban_increment_contract.wasm

This returns the hash of the Wasm bytes, like 6ddb28e0980f643bb97350f7e3bacb0ff1fe74d846c6d4f2c625e766210fbb5b. Now you can use --wasm-hash with deploy rather than --wasm:

stellar contract deploy \
--wasm-hash 6ddb28e0980f643bb97350f7e3bacb0ff1fe74d846c6d4f2c625e766210fbb5b \
--source alice \
--network testnet

This command will return the contract id (e.g. CACDYF3CYMJEJTIVFESQYZTN67GO2R5D5IUABTCUG3HXQSRXCSOROBAN), and you can use it to invoke the contract like we did in previous examples.

stellar contract invoke \
--id CACDYF3CYMJEJTIVFESQYZTN67GO2R5D5IUABTCUG3HXQSRXCSOROBAN \
--source alice \
--network testnet \
-- \
increment

You should see the following output:

1

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 RPC team maintains Docker containers that makes this as straightforward as possible. See the RPC reference for details.

Up next

Ready to turn these deployed contracts into a simple web application? Head over to the Build a Dapp Frontend section.