MidnightContract
High-level interface for calling Midnight smart contract circuits from Android.
Wraps the full pipeline: state fetch → circuit execution → ZK proving → balancing → submission. The developer never touches hex strings, JS expressions, or manual orchestration.
val bboard = MidnightContract.create(config) {
name = "bboard"
contractJs = assets.open("runtime/bboard-contract-iife.js")
address = "4b459404..."
witness("localSecretKey") { WitnessResult(null, secretKeyBytes) }
initialPrivateState = mapOf("secretKey" to ByteArray(32))
coinPublicKey = walletKeys.coinPublicKey
}
val receipt = bboard.call("post", "Hello from Android!")Types
DSL builder for creating a MidnightContract.
Per-key outcome of a readMany batch: the circuit's JSON result or its error message.
Functions
Call a circuit and submit the transaction to the blockchain.
Idempotent single call (#254): if isDoneOnLedger is already true the on-chain effect is present, so this SKIPS the call and returns null (no double-submit); otherwise it runs call and returns the receipt.
Deploy a new contract instance to the blockchain.
Read the contract's ledger state losslessly.
Observe this contract's ledger state as it changes on-chain (#255).
Execute and prove a circuit without submitting (offline mode).
Call a view/getter circuit and return its result as JSON — no proving, no transaction. Reads a contract's computed views (e.g. a treasury balance or a proposal struct) that aren't exposed as raw ledger fields via observeLedger. BigInt → decimal string, Bytes → hex, structs preserved; parse the JSON per circuit. A read-only handle (no signing keys) is sufficient.
Read MANY view circuits in one shot: ONE state fetch, ONE engine session, every circuit against the SAME state snapshot (each isolated on a native clone). Failures are captured per key instead of failing the batch — probing patterns (enumerate proposals until the contract's not-found assert) read the error from the outcome.