forContract

suspend fun forContract(contractId: String, rpcUrl: String, network: Network): ContractClient

Create a ContractClient for a contract with spec loaded from the network (RECOMMENDED).

This is the primary way to create a ContractClient. It loads the contract specification from the network, enabling:

  • Automatic type conversion (native Kotlin types → XDR)

  • Method name validation

  • Contract introspection

  • Manual result parsing helpers (funcResToNative)

Throws an exception if the contract spec cannot be loaded.

Return

ContractClient with contract spec

Parameters

contractId

The contract ID (C... address)

rpcUrl

The RPC server URL

network

The network (TESTNET/PUBLIC)

Throws

if contract spec not found or cannot be loaded