executeCircuit

suspend fun executeCircuit(contractJs: String, contractAddress: String, circuitName: String, circuitArgs: List<String> = emptyList(), witnesses: Map<String, WitnessProvider>, initialPrivateState: String, coinPublicKey: ByteArray, networkId: String = "undeployed", onChainStateHex: String? = null, ledgerParametersHex: String? = null): ExecutionResult

Execute a contract circuit and assemble an UnprovenTransaction.

Return

The assembled UnprovenTransaction as hex-encoded SCALE bytes

Parameters

contractJs

Compiled contract JavaScript (IIFE format, no ES module imports)

contractAddress

Hex-encoded contract address (64 chars)

circuitName

The impure circuit to execute (e.g., "post", "takeDown")

circuitArgs

JS expressions for circuit arguments (inserted into JS code)

witnesses

Map of witness name → WitnessProvider callback.

initialPrivateState

JS expression for the initial private state object

coinPublicKey

The coin public key bytes (32 bytes)

networkId

Network ID for the transaction (default: "undeployed")

onChainStateHex

SCALE-encoded on-chain contract state from the indexer. When provided, circuit execution uses this state instead of contract.initialState(). Required for calling already-deployed contracts where the on-chain state may differ from the contract's initial state.

ledgerParametersHex

SCALE-encoded ledger parameters from the indexer. Required for correct gas computation — the node uses these parameters' cost model to validate the transaction. If omitted, falls back to the initial cost model (only correct on a fresh chain with no parameter updates).

Throws

if circuit execution or tx assembly fails