Skill Guide — This guide walks you through building a copyable reference implementation. For the final, production-ready code, see the full implementation. Also see the Skills Philosophy.
Building an Ethers-style Contract
This guide demonstrates how to build a type-safe, ethers-v6-compatibleContract abstraction using low-level @tevm/voltaire primitives. This approach gives you a powerful, fully-customizable contract wrapper that you own and control.
Philosophy
Instead of providing a rigid, one-size-fits-allContract object, Voltaire gives you the tools to build your own. You get an ethers-compatible API without the dependency, allowing you to tailor it to your specific needs.
Core Primitives
We’ll use a few key Voltaire primitives to build our contract:Abi: For encoding and decoding ABI data.Hex: For working with hexadecimal strings.- A JSON-RPC
runner(like a provider or signer) that can makerequest()calls.
Building EthersContract
Let’s start with a simplified EthersContract implementation. Our goal is a function that takes a contract target, abi, and a runner, and returns an object that lets us call contract methods.
We can achieve this using a Proxy, which intercepts calls to methods that don’t exist on our object and interprets them as contract calls.
- ABI Parsing:
Abi(abi)creates a reusable interface for encoding/decoding. - Proxy Interception: The
Proxycatches calls likeusdc.balanceOf(...). - Encoding:
abiInterface.encode()creates thedatapayload for the JSON-RPC request. - RPC Calls: It uses the
runnerto send eithereth_calloreth_sendTransaction. - Decoding:
abiInterface.decode()parses theeth_callresult.
Building a ContractFactory
To deploy contracts, we need a ContractFactory. It takes the ABI and bytecode, and its deploy method encodes constructor arguments and sends a transaction with the combined bytecode.
Here’s a simplified example:
Type Safety
You can get full TypeScript inference by usingas const on your ABI. The full reference implementation includes comprehensive types that provide autocomplete and type-checking for function arguments and return values.
Full Reference Implementation
The simplified examples above illustrate the core concepts. The full implementation inexamples/ethers-contract/ is production-ready and includes many more features:
- Explicit
staticCall,send,estimateGas, andpopulateTransactionmethods. - Event filtering and querying (
queryFilter). - Event subscriptions (
on,once,off). - Robust error handling and revert reason decoding.
- Deployment address calculation.
- Comprehensive TypeScript types.
Installation
To use the full implementation, copy theexamples/ethers-contract/ directory into your project:

