How to deploy a smart contract in Rust

thelief

Lief Storer

Posted on June 21, 2023

How to deploy a smart contract in Rust

Soroban contracts are small programs written in the Rust programming language. In this tutorial we'll walk you through setting up your local environment so that you're ready to build Smart Contracts in Rust. If you're wondering why Rust and not Solidity, read this to compare the platforms.

To build and develop contracts you need only a couple prerequisites:

  • A Rust toolchain

  • An editor that supports Rust

  • Soroban CLI

  • Install Rust

If you use macOS, Linux, or another Unix-like OS, the simplest method to install a Rust toolchain is to install rustup. Install rustup with the following command.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

If you use Windows, or need an alternative method of installing Rust, check out:
https://www.rust-lang.org/tools/install

Install the target

Install the wasm32-unknown-unknown target.

rustup target add wasm32-unknown-unknown

Configure an Editor

Many editors have support for Rust. Visit the following link to find out how to configure your editor:
https://www.rust-lang.org/tools

A popular editor is Visual Studio Code:

Visual Studio Code editor.
Rust Analyzer for Rust language support.
CodeLLDBfor step-through-debugging.

Install the Soroban CLI

The Soroban CLI can execute Soroban contracts in the same environment the contract will execute on network, however in a local sandbox.

Install the Soroban CLI using cargo install.

cargo install --locked --version 0.8.0 soroban-cli

INFO
Report issues and share feedback about the Soroban CLI here
.

Usage

Run the soroban command and you should see output like below.

soroban

❯ soroban
Build, deploy, & interact with contracts; set identities to sign with; configure networks; generate keys; and more.

Intro: https://soroban.stellar.org
CLI Reference: https://github.com/stellar/soroban-tools/tree/main/docs/soroban-cli-full-docs.md

Usage: soroban <COMMAND>

Commands:
  contract    Tools for smart contract developers
  config      Read and update config
  events      Watch the network for contract events
  lab         Experiment with early features and expert tools
  version     Print version information
  completion  Print shell completion code for the specified shell

Options:
  -h, --help     Print help (see more with '--help')
  -V, --version  Print version
Enter fullscreen mode Exit fullscreen mode

Here's a video to help guide you through the process.

Once you've completed the initial setup, check out the Hello World contract deployment documentation here.

💖 💪 🙅 🚩
thelief
Lief Storer

Posted on June 21, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

How to deploy a smart contract in Rust
smartcontract How to deploy a smart contract in Rust

June 21, 2023