Hello Soroban
Let's create our first Soroban smart contract
#![no_std]
use soroban_sdk::{contract, contractimpl, Env, log};
#[contract]
pub struct HelloWorld;
#[contractimpl]
impl HelloWorld {
/// Welcome to Soroban-by-example!
///
/// The function logs a "Hello World" message to the Soroban environment.
///
/// Have fun exploring Soroban!
pub fn say_hello(env: Env) {
log!(&env, "Hello World");
}
}
Guide
#![no_std]
This attribute prevents linking to the standard library, making the code lighter and more efficient for Soroban contracts. It's big so we save on size.
use soroban_sdk::{contract, contractimpl, Env, log}
Imports stuffs from the Soroban SDK. Env
is basic Soroban type, we need it because we can't use the Rust standard library.
#[contract]
Marks the struct as a Soroban smart contract. Soroban smart contracts are defined as Rust structs.
#[contractimpl]
Marks the implementation block as containing contract methods and transforms it to code that Soroban can evaluate directly
pub
Marks a function as external, meaning it can be invoked outside of the context of the contract code itself.
Live Example
Loading playground...