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
Reading Contract State
Theread 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:- ABI-encode the function call with arguments
- Send
eth_callto the provider - ABI-decode the return data
Writing to Contracts
Thewrite interface sends transactions via eth_sendTransaction. Requires gas and modifies state.
Send Transaction
Approve Spender
Estimate Gas First
UseestimateGas to simulate before sending:
Manual ABI Encoding
For advanced use cases, access theabi 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
Related
- Contract Overview - Contract module introduction
- Read Methods - Detailed read documentation
- Write Methods - Detailed write documentation
- Gas Estimation - Gas estimation details
- Events - Streaming contract events

