@0xdoublesharp/hardhat-abi-typegen
v0.2.0
Published
Hardhat plugin for abi-typegen — auto-generate typed bindings on compile
Maintainers
Readme
@0xdoublesharp/hardhat-abi-typegen
Hardhat plugin for abi-typegen. Generates typed bindings from Solidity ABI artifacts on every hardhat compile. Downloads the pre-built abi-typegen binary for your platform automatically.
Install
npm install -D @0xdoublesharp/hardhat-abi-typegen
yarn add -D @0xdoublesharp/hardhat-abi-typegen
pnpm add -D @0xdoublesharp/hardhat-abi-typegenSetup
Add to hardhat.config.ts:
import "@0xdoublesharp/hardhat-abi-typegen";
const config: HardhatUserConfig = {
solidity: "0.8.34",
typegen: {
out: "src/generated", // output directory (default: "src/generated")
target: "viem", // target name or comma-separated targets
wrappers: true, // emit typed wrappers (default: true)
contracts: ["Token"], // optional — limit to named contracts
exclude: ["*Test", "*Mock"],// optional — exclude by glob pattern
},
};
export default config;Usage
Types are generated automatically after every compile:
npx hardhat compile
# → abi-typegen: generated 5 contract(s) → src/generatedOr generate directly:
npx abi-typegen generate --hardhat --target viemConfiguration
| Option | Type | Default | Description |
|---|---|---|---|
| out | string | "src/generated" | Output directory for generated files |
| target | string \| string[] | "viem" | Target name, comma-separated targets, or array of targets (see below) |
| wrappers | boolean | true | Emit typed wrapper files when supported |
| contracts | string[] | [] | Limit to named contracts (empty = all) |
| exclude | string[] | [] | Exclude contracts matching glob patterns |
Targets
| Target | Flag | Language | Ecosystem |
|---|---|---|---|
| viem | viem | TypeScript | viem |
| zod | zod | TypeScript | Zod 4 |
| wagmi | wagmi | TypeScript | wagmi v2 |
| ethers v6 | ethers | TypeScript | ethers v6 |
| ethers v5 | ethers5 | TypeScript | ethers v5 |
| web3.js | web3js | TypeScript | web3.js v4 |
| Python | python | Python | web3.py |
| Go | go | Go | go-ethereum |
| Rust | rust | Rust | alloy |
| Swift | swift | Swift | web3swift |
| C# | csharp | C# | Nethereum |
| Kotlin | kotlin | Kotlin | web3j |
| Solidity | solidity | Solidity | External interfaces |
| YAML | yaml | YAML | Human-readable ABI descriptions |
Target aliases: ethers6 → ethers, web3 → web3js, cs → csharp, kt → kotlin, sol → solidity, yml → yaml
Multi-target examples — each target gets its own output subdirectory:
target: "viem,python,rust" // comma-separated string
target: ["viem", "python", "rust"] // array of stringsNotes
- When using
target: "zod", install the latestzodpackage in the consuming project - Use comma-separated multi-target generation instead of the removed
allandall-tsaliases
See github.com/doublesharp/abi-typegen for full documentation.
