createContract

fun createContract(wasmId: String, address: Address, constructorArgs: List<SCValXdr>? = null, salt: ByteArray? = null): InvokeHostFunctionOperation

Creates an InvokeHostFunctionOperation for creating/deploying a contract.

This operation deploys a contract instance from previously uploaded WASM code, optionally passing constructor arguments to initialize the contract.

Return

An InvokeHostFunctionOperation for creating the contract

Example

// Deploy contract without constructor arguments
val createOp = InvokeHostFunctionOperation.createContract(
wasmId = "abc123...", // 64-character hex string
address = Address(deployerAccountId)
)

// Deploy contract with constructor arguments (e.g., token contract)
val createTokenOp = InvokeHostFunctionOperation.createContract(
wasmId = "def456...",
address = Address(deployerAccountId),
constructorArgs = listOf(
Address(adminId).toSCVal(),
Scv.toUint32(8u), // decimals
Scv.toString("TokenName"),
Scv.toString("TOKEN")
)
)

Parameters

wasmId

The 32-byte hash of the uploaded WASM code (hex-encoded, 64 characters)

address

The address to use for deriving the contract ID

constructorArgs

Optional constructor arguments for contracts that require initialization

salt

Optional 32-byte salt for contract ID derivation (random if null)

See also