Skip to content
This repository was archived by the owner on Aug 21, 2024. It is now read-only.

Latest commit

 

History

History
188 lines (130 loc) · 7.02 KB

setup.mdx

File metadata and controls

188 lines (130 loc) · 7.02 KB
sidebar_position title description sidebar_custom_props
0
Setup
Install and configure Rust to deploy smart contracts.

:::danger These are not the droids you're looking for

This page has been migrated to the Stellar Developers documentation. Please click here for the most up-to-date information

:::

<title>Install and configure Rust to deploy smart contracts.</title>

Soroban contracts are small programs written in the Rust programming language.

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

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:

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 latest released version of Soroban CLI using cargo install.

cargo install --locked 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 [OPTIONS] <COMMAND>

Commands:
  completion  Print shell completion code for the specified shell
  config      Deprecated, use `soroban keys` and `soroban network` instead
  contract    Tools for smart contract developers
  events      Watch the network for contract events
  keys        Create and manage identities including keys and addresses
  lab         Experiment with early features and expert tools
  network     Start and configure networks
  version     Print version information

Options:
      --global                     Use global config
  -f, --filter-logs <FILTER_LOGS>  Filter logs output. To turn on "soroban_cli::log::footprint=debug" or off "=off". Can also use env var `RUST_LOG`
  -q, --quiet                      Do not write logs to stderr including `INFO`
  -v, --verbose                    Log DEBUG events
      --very-verbose               Log DEBUG and TRACE events [aliases: vv]
      --list                       List installed plugins. E.g. `soroban-hello`
  -h, --help                       Print help (see more with '--help')
  -V, --version                    Print version

TESTING_OPTIONS:
      --config-dir <CONFIG_DIR>  Location of config directory, default is "."

:::info

Protip: You can use soroban completion to generate shell completion for bash, elvish, fish, powershell, and zsh. You should absolutely try it out. It will feel like a super power!!

To enable autocomplete in the current bash shell, run:

source <(soroban completion --shell bash)

To enable autocomplete permanently in future bash shells, run:

echo "source <(soroban completion --shell bash)" >> ~/.bashrc

Users of non-bash shells may need to adapt the above commands to suit their needs.

:::

Configuring the CLI for Testnet

Soroban has a test network called Testnet that you can use to deploy and test your smart contracts. It's a live network, but it's not the same as the Stellar public network. It's a separate network that is used for development and testing, so you can't use it for production apps. But it's a great place to test your contracts before you deploy them to the public network.

To configure your CLI to interact with Testnet, run the following command:

soroban network add --global testnet \
  --rpc-url https://soroban-testnet.stellar.org:443 \
  --network-passphrase "Test SDF Network ; September 2015"

Note the --global flag. This creates a file in your home folder's ~/.config/soroban/network/testnet.toml with the settings you specified. This means that you can use the --network testnet flag in any Soroban CLI command to use this network from any directory or filepath on your system.

If you want project-specific network configurations, you can omit the --global flag, and the networks will be added to your working directory's .soroban/network folder instead.

Configure an Identity

When you deploy a smart contract to a network, you need to specify an identity that will be used to sign the transactions.

Let's configure an identity called alice. You can use any name you want, but it might be nice to have some named identities that you can use for testing, such as alice, bob, and carol.

soroban keys generate --global alice --network testnet

You can see the public key of alice with:

soroban keys address alice

Like the Network configs, the --global means that the identity gets stored in ~/.config/soroban/identity/alice.toml. You can omit the --global flag to store the identity in your project's .soroban/identity folder instead.

By default, soroban keys generate will fund your account using Friendbot. If you don't want this behavior, run this command with --no-fund.