rustmultiinfrastructurebeginner

Soroban Hello World

A minimal smart contract for Stellar's Soroban platform written in Rust.

All snippets

Code

rust
#![no_std]
use soroban_sdk::{contract, contractimpl, symbol_short, Env, Symbol};

const COUNTER: Symbol = symbol_short!("COUNTER");

#[contract]
pub struct HelloContract;

#[contractimpl]
impl HelloContract {
    pub fn increment(env: Env) -> i32 {
        let mut count: i32 = env.storage().instance().get(&COUNTER).unwrap_or(0);
        count += 1;
        env.storage().instance().set(&COUNTER, &count);
        count
    }
}

Explanation

Soroban is Stellar's smart contract platform. Contracts use no_std Rust and the soroban_sdk crate. Storage is accessed through env.storage(). The #[contract] and #[contractimpl] macros define the contract interface.

sorobanstellarwasmrust