npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

etherlib-generator

v0.2.1

Published

Manage and generate different ethereum library codes from config(ABIs, networks, chains, address)

Readme

etherlib-generator

npm version npm downloads bundle JSDocs License

Manage and generate different ethereum library codes from config(ABIs, networks, chains, address)

library library library library

Features ✨

  • Simplified Contract Interaction - Generate type-safe contract interfaces from ABIs
  • Multi-Library Support - Generate code for different Ethereum libraries (Viem, Ethers.js)
  • Chain Management - Configure and manage multiple blockchain networks
  • Address Management - Organize contract addresses across different chains
  • Plugin System - Extensible architecture with plugins for different libraries and frameworks
  • Type Safety - Full TypeScript support for enhanced developer experience

Installation 📦

# npm
pnpm add etherlib-generator

Quick Start 🏁

1. Create Configuration File

Create an etherlib.config.ts file in your project root:

import { defineConfig } from 'etherlib-generator'
import { hardhat, viem } from 'etherlib-generator/plugins'

import { erc20Abi } from 'viem'
import { mainnet } from 'viem/chains'

export default defineConfig({
  // Output directory for generated code
  output: 'src/generated',

  // Manually add contract ABIs
  fragments: {},
  // Manually add contract addresses
  addresses: {},
  // Manually add chain networks
  chains: {},

  plugins: [
    // Collect configs(deployedAddress, network, fragments) from Hardhat
    hardhat(),
    // Generate code for viem
    viem(), // or ethers()
  ],
})

2. Generate Code

Run the following command to generate code based on your configuration:

npx etherlib generate

3. Use Generated Code(viem)

Import and use the generated code in your application:

import { chains, client, connection, getContractCounter } from './src/generated'

// Indicate chain(only query)
connection.connect(chains.ethereum)

// Indicate chain and account(metamask/eip-1193)
connection.connect(chains.ethereum, { type: 'eip-1193', value: window.ethereum })

// Indicate chain and account(provideKey)
connection.connect(chains.ethereum, { type: 'provideKey', value: 'your-private-key' })

const blockNumber = await client.getBlockNumber()

// Use the generated contract functions

// auto find chain address, client
const counter = getContractCounter()
// or manually set the address and client
const counter = getContractCounter({
  address: '0xYourContractAddress',
  client: createPublicClient({/* ... */}), // or { client, wallet }
})

// Call contract functions
const num = await counter.read.x()

connection represents the current session being used. It is connected via the connection.connect() method, specifying the chain and account to be used, which will affect the global usage without the need to manually create client/wallet or pass configuration information when using contracts later.

connection is implemented based on proxy, which is a special object that allows you to dynamically update configurations through proxy at runtime. This allows you to use the same contract instances in different environments without having to recreate them each time.

import { chain, chains, client, getContractCounter } from './src/generated'

// Set up current chain
chain.proxy.update(chains.ethereum)
// Set up your client or wallet
client.proxy.update(createPublicClient({/* your options */}))
wallet.proxy.update(createWalletClient({/* your options */}))

const blockNumber = await client.getBlockNumber()

// Use the generated contract functions

// auto find chain address, client
const counter = getContractCounter()
// or manually set the address and client
const counter = getContractCounter({
  address: '0xYourContractAddress',
  client: createPublicClient({/* ... */}), // or { client, wallet }
})

// Call contract functions
const num = await counter.read.x()
import { client, getContractCounter } from './src/generated'

const counter = getContractCounter()

client.proxy.update(createPublicClient({/* ethereum */}))
const ethereumBlockNumber = await client.getBlockNumber()
counter.read.x() // call ethereum counter contract

client.proxy.update(createPublicClient({/* sepolia */}))
const sepoliaBlockNumber = await client.getBlockNumber()
counter.read.x() // call sepolia counter contract

Updating the chain will help contracts automatically find the correct contract address

import { chain, chains } from './src/generated'

chain.proxy.update(chains.sepolia)

// find chains.sepolia.contracts.Counter.address
const counter = getContractCounter()

Hardhat Network Expansion

Expand the network field by importing etherlib-generator/hardhat-network to reference the chain network in the Hardhat configuration.

/// <reference types="etherlib-generator/hardhat-network" />

import type { HardhatUserConfig } from 'hardhat/config'

const config: HardhatUserConfig = {
  networks: {
    sepolia: {
      type: 'http',
      chainType: 'l1',
      url: 'Your RPC URL',
      chainId: 11155111,
      accounts: [configVariable('SEPOLIA_PRIVATE_KEY')],
      // more options...
      icon: 'https://sepolia.dev/icon.svg',
      name: 'Sepolia',
      testnet: true,
      currency: {
        name: 'Sepolia Ether',
        symbol: 'ETH',
        decimals: 18,
      },
      contracts: {
        USDT: '0x..',
      },
      explorer: {
        name: 'Sepolia Etherscan',
        url: '...',
        api: '...',
      },
    },
  },
}

export default config

Configuration Options 🛠️

Output

Specify where generated code should be saved:

Fragments

Define contract ABIs

const config = defineConfig({
  // ...
  fragments: {
    ERC20: erc20Abi,
    MyToken: [/* abi content */],
  }
  // ...
})

Addresses

Configure contract addresses by chain ID:

const config = defineConfig({
  addresses: {
    1: { // Ethereum Mainnet
      MyToken: '0x1234567890123456789012345678901234567890',
    },
    5: { // Goerli
      MyToken: '0x0987654321098765432109876543210987654321',
    },
  }
  // ...
})

Chains

Configure blockchain chain networks:

const config = defineConfig({
  // ...
  chains: {
    ethereum: mainnet,
    sepolia: {
      name: 'Sepolia',
      id: 11155111,
      rpc: 'https://rpc.sepolia.org',
      testnet: true,
    },
  }
  // ...
})

Plugins

Add plugins for different libraries:

const config = defineConfig({
  // ...
  plugins: [
    hardhat(),
    viem(), // or // ethers()
  ]
  // ...
})

CLI Commands 💻

  • etherlib generate: Generate code based on your configuration
  • etherlib --help: Show help information

Learn More 📚

Check out the playground directory for more examples.

License

MIT License © Hairyf