Crate soroban_sdk

Source
Expand description

Soroban SDK supports writing smart contracts for the Wasm-powered Soroban smart contract runtime, deployed on Stellar.

§Docs

See developers.stellar.org for documentation about building smart contracts for Stellar.

§Migrating Major Versions

See _migrating for a summary of how to migrate from one major version to another.

§Examples

use soroban_sdk::{contract, contractimpl, vec, symbol_short, BytesN, Env, Symbol, Vec};

#[contract]
pub struct Contract;

#[contractimpl]
impl Contract {
    pub fn hello(env: Env, to: Symbol) -> Vec<Symbol> {
        vec![&env, symbol_short!("Hello"), to]
    }
}

#[test]
fn test() {
    let env = Env::default();
    let contract_id = env.register(Contract, ());
    let client = ContractClient::new(&env, &contract_id);

    let words = client.hello(&symbol_short!("Dev"));

    assert_eq!(words, vec![&env, symbol_short!("Hello"), symbol_short!("Dev"),]);
}

More examples are available at:

Re-exports§

pub use events::Topics;

Modules§

_migrating
Migrating from v21 to v22
auth
Auth contains types for building custom account contracts.
crypto
Crypto contains functions for cryptographic functions.
deploy
Deploy contains types for deploying contracts.
events
Events contains types for publishing contract events.
iter
Iterators for use with collections like Map, Vec.
ledger
Ledger contains types for retrieving information about the current ledger.
logs
Logging contains types for logging debug events.
prng
Prng contains a pseudo-random number generator.
storage
Storage contains types for storing data for the currently executing contract.
testutilstestutils
Utilities intended for use when testing.
token
Token contains types for calling and accessing token contracts, including the Stellar Asset Contract.
xdr
Convert values to and from Bytes.

Macros§

assert_in_contract
Assert in contract asserts that the contract is currently executing within a contract. The macro maps to code when testutils are enabled or in tests, otherwise maps to nothing.
assert_with_error
Assert a condition and panic with the given error if it is false.
bytes
Create a Bytes with an array, or an integer or hex literal.
bytesn
Create a BytesN with an array, or an integer or hex literal.
contractfile
Import a contract from its WASM file, generating a constant holding the contract file.
contractimport
Import a contract from its WASM file, generating a client, types, and constant holding the contract file.
contractmeta
Adds a serialized SCMetaEntry::SCMetaV0 to the WASM contracts custom section under the section name ‘contractmetav0’. Contract developers can use this to append metadata to their contract.
impl_bytesn_repr
log
Log a debug event.
map
Create a Map with the given key-value pairs.
panic_with_error
Panic with the given error.
symbol_short
Create a short Symbol constant with the given string.
vec
Create a Vec with the given items.

Structs§

Address
Address is a universal opaque identifier to use in contracts.
Bytes
Bytes is a contiguous growable array type containing u8s.
BytesN
BytesN is a contiguous fixed-size array type containing u8s.
ConversionError
Error type indicating a failure to convert some type to another; details of the failed conversion may be written to the debug log, when possible.
Duration
Duration holds a 64-bit unsigned integer.
Env
The Env type provides access to the environment the contract is executing within.
I256
I256 holds a 256-bit signed integer.
Map
Map is a ordered key-value dictionary.
String
String is a contiguous growable array type containing u8s.
Symbol
Symbol is a short string with a limited character set.
Timepoint
Timepoint holds a 64-bit unsigned integer.
U256
U256 holds a 256-bit unsigned integer.
Val
Raw value of the Soroban smart contract platform that types can be converted to and from for storing, or passing between contracts.
Vec
Vec is a sequential and indexable growable collection type.

Enums§

InvokeError
InvokeError captures errors returned from the invocation of another contract.

Traits§

ConstructorArgs
FromVal
Used to do conversions between values in the Soroban environment.
IntoVal
Used to do conversions between values in the Soroban environment.
TryFromVal
Used to do conversions between values in the Soroban environment. Trait for types that can be fallibly converted to another type V, analogous to the standard Rust type TryFrom, but making use of the provided Env implementation E in order to convert parts of the type that require it. Mainly this exists because Val types that contain object handles need to delegate to the environment to look up and extract the content of those handles.
TryIntoVal
Used to do conversions between values in the Soroban environment. The opposite trait to TryFromVal, analogous to the way that TryInto exists as an opposite to TryFrom. Exists only for convenience of doing conversions via .try_into_val(e) or specifying convertability with a bound like TryIntoVal<E,Other>.

Attribute Macros§

contract
Marks a type as being the type that contract functions are attached for.
contractargs
Generates a type that helps build function args for a contract trait.
contractclient
Generates a client for a contract trait.
contracterror
Generates conversions from the repr(u32) enum from/into an Error.
contractimpl
Exports the publicly accessible functions to the Soroban environment.
contracttype
Generates conversions from the struct/enum from/into a Val.