Skip to main content

Create a Project

Once you've Setup your development environment, you're ready to create Soroban contracts. Creating projects is done using the Rust tool, cargo.

Create a new Rust library using the cargo new command.

cargo new --lib [project-name]

Open the Cargo.toml, it should look something like this:

Cargo.toml
[package]
name = "project-name"
version = "0.1.0"
edition = "2021"

Configure the Library Type

Add the crate-type configuration, required for building contracts.

[lib]
crate-type = ["cdylib", "rlib"]

Import soroban-sdk and Features

Add the following sections to the Cargo.toml that will import the soroban-sdk, and configure a set of features explained below.

caution

The soroban-sdk is in early development. Report issues here.

[dependencies]
soroban-sdk = "0.0.4"

[dev_dependencies]
soroban-sdk = { version = "0.0.4", features = ["testutils"] }

[features]
testutils = ["soroban-sdk/testutils"]

The features list includes a testutils feature, which will cause additional test utilities to be generated for calling the contract in tests.

info

The testutils test utilities are automatically enabled inside Rust unit tests inside the same crate as your contract. If you write Rust integration tests, or write tests from another crate, you'll need to add #[cfg(feature = "testutils")] to those tests and enable the testutils feature when running your tests with cargo test --features testutils to be able to use those test utilities.

Configure the release Profile

Configuring the release profile to optimize the contract build is critical. Soroban contracts have a maximum size of 256KB. Rust programs, even small ones, without these configurations almost always exceed this size.

Add the following to your Cargo.toml.

[profile.release]
opt-level = "z"
overflow-checks = true
debug = 0
strip = "symbols"
debug-assertions = false
panic = "abort"
codegen-units = 1
lto = true

Wrapping it Up

The steps below should produce a Cargo.toml that looks like so.

Cargo.toml
[lib]
crate-type = ["cdylib", "rlib"]

[features]
testutils = ["soroban-sdk/testutils"]

[dependencies]
soroban-sdk = "0.0.4"

[dev_dependencies]
soroban-sdk = { version = "0.0.4", features = ["testutils"] }

[profile.release]
opt-level = "z"
overflow-checks = true
debug = 0
strip = "symbols"
debug-assertions = false
panic = "abort"
codegen-units = 1
lto = true