Skip to main content
Skill — Copyable reference implementation. Use as-is or customize. See Skills Philosophy.

Contract Interaction

This guide covers reading contract state, writing transactions, and manual ABI encoding/decoding using Voltaire primitives.
Voltaire provides a reference implementation for Contract abstraction, not a library export. Copy the implementation from Contract Pattern into your project and customize as needed. See Primitives Philosophy for why.

Prerequisites

  • A provider (EIP-1193 compatible)
  • Contract address and ABI
  • Contract implementation copied from Contract Pattern or examples/contract/

Setup

Validate ABIs with the Effect schema to catch malformed items before calling into Contract helpers.

Reading Contract State

The read interface executes view/pure functions via eth_call. No gas required.

Single Read

Multiple Reads in Parallel

How Read Works

Under the hood, read methods:
  1. ABI-encode the function call with arguments
  2. Send eth_call to the provider
  3. ABI-decode the return data

Writing to Contracts

The write interface sends transactions via eth_sendTransaction. Requires gas and modifies state.

Send Transaction

Approve Spender

Write methods return immediately after transaction submission. The transaction may still be pending or could revert during execution.

Estimate Gas First

Use estimateGas to simulate before sending:

Manual ABI Encoding

For advanced use cases, access the abi instance directly.

Encode Function Call

Decode Return Values

Build Custom Transaction

Return Value Handling

Single Output

Functions with one output return the value directly:

Multiple Outputs

Functions with multiple outputs return an array:

Error Handling

Complete Example