Crate soroban_sdk

source ·
Expand description

Soroban SDK supports writing programs for the Soroban smart contract platform.

§Docs

See soroban.stellar.org for documentation.

§Examples

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

#[contract]
pub struct HelloContract;

#[contractimpl]
impl HelloContract {
    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(None, HelloContract);
    let client = HelloContractClient::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 https://soroban.stellar.org/docs/category/basic-tutorials and https://soroban.stellar.org/docs/category/advanced-tutorials.

Modules§

  • Crypto contains functions for cryptographic functions.
  • Deploy contains types for deploying contracts.
  • Events contains types for publishing contract events.
  • Iterators for use with collections like Map, Vec.
  • Ledger contains types for retrieving information about the current ledger.
  • Logging contains types for logging debug events.
  • Prng contains a pseudo-random number generator.
  • Storage contains types for storing data for the currently executing contract.
  • testutilstestutils
    Utilities intended for use when testing.
  • Token contains types for calling and accessing token contracts, including the Stellar Asset Contract.
  • Convert values to and from Bytes.

Macros§

  • Assert a condition and panic with the given error if it is false.
  • Create a Bytes with an array, or an integer or hex literal.
  • Create a BytesN with an array, or an integer or hex literal.
  • Import a contract from its WASM file, generating a constant holding the contract file.
  • Import a contract from its WASM file, generating a client, types, and constant holding the contract file.
  • 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.
  • Log a debug event.
  • Create a Map with the given key-value pairs.
  • Panic with the given error.
  • Create a short Symbol constant with the given string.
  • Create a Vec with the given items.

Structs§

  • Address is a universal opaque identifier to use in contracts.
  • Bytes is a contiguous growable array type containing u8s.
  • BytesN is a contiguous fixed-size array type containing u8s.
  • 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 holds a 64-bit unsigned integer.
  • The Env type provides access to the environment the contract is executing within.
  • I256 holds a 256-bit signed integer.
  • Map is a ordered key-value dictionary.
  • String is a contiguous growable array type containing u8s.
  • Symbol is a short string with a limited character set.
  • Timepoint holds a 64-bit unsigned integer.
  • U256 holds a 256-bit unsigned integer.
  • Raw value of the Soroban smart contract platform that types can be converted to and from for storing, or passing between contracts.
  • Vec is a sequential and indexable growable collection type.

Enums§

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

Traits§

  • Used to do conversions between values in the Soroban environment.
  • Used to do conversions between values in the Soroban environment.
  • 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.
  • 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§

  • Marks a type as being the type that contract functions are attached for.
  • Generates a client for a contract trait.
  • Generates conversions from the repr(u32) enum from/into an Error.
  • Exports the publicly accessible functions to the Soroban environment.
  • Generates conversions from the struct/enum from/into a Val.