Skip to main content

Setup

Stellar smart 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

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 Stellar CLI

The Stellar CLI can execute smart contracts on futurenet, testnet, mainnet, as well as in a local sandbox.

The latest stable release is v22.0.1.

Install

There are a few ways to install the latest release of Stellar CLI.

Install with Homebrew (macOS, Linux):

brew install stellar-cli

Install with cargo from source:

cargo install --locked [email protected] --features opt
info

Report issues and share feedback about the Stellar CLI here.

Documentation

The auto-generated comprehensive reference documentation is available here.

Autocompletion

You can use stellar completion to generate shell completion for different shells. You should absolutely try it out. It will feel like a super power!

To enable autocomplete on the current shell session:

source <(stellar completion --shell bash)

To enable autocomplete permanently, run the following command, then restart your terminal:

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

Configuring the CLI for Testnet

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. Notice that the account will be funded using Friendbot.

stellar keys generate --global alice --network testnet --fund

You can see the public key of alice with:

stellar keys address alice

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

info

We previously used ~/.config/soroban (global) and .soroban (local) as the configuration directories. These directories are still supported, but the preferred name is now ~/.config/stellar and .stellar moving forward.