This is for building an SDK for writing smart contracts.
Functionality
Value Conversions
- Val encode/decode
- Object encode/decode
- Symbol encode/decode
- Option encode/decode
- Error encode/decode
Host Functions
The host functions defined in env.json are functions callable from within the Wasm Guest environment. These need to be available to contracts to call, in some form, ideally wrapped so that contracts have a nicer interface. Host functions have friendly names in the file above, such asget_ledger_version, however in the Wasm they are only importable via short names, such as x.4. The letter proceeding the dot is the module, and the value after the dot is the function name. The mappins are available in env.rs.
SDK Types
All the types in soroban-sdk should be supported. Notably:User Defined Types
Contracts should be able to create user defined types, such as structs, unions, or enums, and have them be transmitted to the host for storing and transmitted back for loading. SDKs do this by converting objects to and from aVal. In the soroban-sdk this is referred to as a Val.
Structs
Structs with named fields should be translated into aMap with keys as Symbols and the values as the field value, i.e. Map<Symbol, V>.
Structs with unnamed fields should be translated into a Vec with the values as the elements. i.e. Vec<V>.
Unions
Unions (or enums in some languages) with named variants and unit or tuple values should be translated into aVec with the first element as a Symbol of the name of the variant, and zero or more additional elements representing a value stored with the variant.
Enums
Enums with integer values should be translated into au32.
User Defined Errors
Errors areu32 values that are translated into a Error.
Environment Meta Generation
Contracts must contain a Wasm custom section with namecontractenvmetav0 and containing a serialized SCEnvMetaEntry. The interface version stored within should match the version of the host functions supported.
To view the Environment Meta, please consider using Stellar Lab’s Contract Explorer, or Stellar CLI’s command stellar contract info env-meta --contract-id <contract-id>.
Contract Meta Generation
Contracts can optionally include a custom Wasm section namedcontractmetav0, which contains a serialized SCMetaEntry. This section is not used by the network itself, but allows contracts to embed arbitrary metadata, including contract name, version, author, supported interfaces, source repo, or home domain. Applications and tooling can read this metadata to provide richer developer experiences, better indexing, or enhanced contract discovery.
To add metadata to Contract Meta, please use the Stellar CLI command stellar contract build --meta <meta>.
To view the Contract Meta, please use the Stellar Lab’s Contract Explorer, or the Stellar CLI command stellar contract info meta --contract-id <contract-id>.
Contract Spec Generation
Contracts should contain a Wasm custom section with namecontractspecv0 and containing a serialized stream of SCSpecEntry. There should be a SCSpecEntry for every function, struct, and union exported by the contract.
To view the Contract Meta, please use the Stellar Lab’s Contract Explorer, or the Stellar CLI command stellar contract info interface --contract-id <contract-id>.
Testing
Any Soroban SDK ideally provides a test environment for executing contract functions in the context of a Soroban runtime environment. The soroban-sdk does this by embedding the Soroban environment Rust library, soroban-env-host. The test environment should include:- Invoking contract functions.
- Integration testing across multiple contracts.