SorobanContractParser

Parses a Soroban contract byte code to extract Environment Meta, Contract Spec, and Contract Meta.

This parser implements the Soroban contract specification as described in: https://developers.stellar.org/docs/tools/sdks/build-your-own

The contract byte code (WASM) contains embedded metadata in custom sections:

  • contractenvmetav0: Environment metadata (protocol version)

  • contractspecv0: Contract specification entries (functions, structs, unions, enums, events)

  • contractmetav0: Contract metadata (key-value pairs for application/tooling use)

Example usage:

val wasmBytes = // ... load WASM file
try {
val contractInfo = SorobanContractParser.parseContractByteCode(wasmBytes)
println("Protocol version: ${contractInfo.envInterfaceVersion}")
contractInfo.specEntries.forEach { entry ->
// Process spec entries
}
} catch (e: SorobanContractParserException) {
println("Failed to parse contract: ${e.message}")
}

Functions

Link copied to clipboard

Parses a Soroban contract byte code to extract Environment Meta, Contract Spec, and Contract Meta.