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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tevm/ethers

v1.0.0-next.42

Published

A collection of ethers.js utilities for working with Tevm

Downloads

15

Readme

CI CI

@tevm/ethers

A ethers.js utilities for Tevm

Try cloning our minimal bun example on github

Don't worry if you aren't familiar with bun. It works with NODE/npm pnpm and yarn too

High level overview

Previously the best way to get typesafe contracts with ethers was typechain typechain improved the dev experience of using contracts via creating typesafe contracts via codegen. Tevm builds on this idea by providing the same benifit purely at runtime without any build or codegen steps.

  • @tevm/ethers exports a single function createEthersContract
  • @tevm/ethers only supports ethers v6 at this time

Installation

To use @tevm/ethers simply set up tevm as normal and add the special @tevm/ethers package

npm install @tevm/ethers ethers@6

API Reference

createEthersContract function

Type

function createEthersContract<TAddresses extends Record<number, Address>, TAbi extends Abi>(
    contract: Pick<TevmContract<any, TAddresses, TAbi, any>, 'abi' | 'addresses'>,
    options: CreateEthersContractOptions<keyof TAddresses & number>
): TypesafeEthersContract<TAbi>

Description Creates a typesafe ethers contract from an tevm contract. This function provides typesafe contracts for Ethereum development with Ethers.js and Tevm.

Params

  • contract: This parameter should be an Tevm contract. It should include the 'abi' and 'addresses' properties.
  • options: This parameter should be an object of type CreateEthersContractOptions. It should include either a chainId or an address, along with the runner, which should be an Ethers.js provider or signer.

Returns The function returns a TypesafeEthersContract. This contract is a typed version of the ethers.js contract instance, which provides type safety and autocompletion for contract methods.

Example

// import a contract with tevm
import {ERC20} from '@openzeppelin/contracts/token/ERC20/ERC20.sol'
import {providers} from 'ethers'
// create a provider or signer for the ethers contract
const provider = new providers.JsonRpcProvider('http://localhost:8545')
// create a typesafe contract
const contract = createEthersContract(myContract, {chainId: 1, runner: provider})
// enjoy typesafety and autocompletion in your ethers contract
const balance = c.balanceOf('0x32307adfFE088e383AFAa721b06436aDaBA47DBE'),

CreateEthersContractOptions Type

Type

type CreateEthersContractOptions<TChainIds extends number> =
  | {
      chainId: TChainIds;
      runner: ContractRunner;
  }
  | {
      address: Address;
      runner: ContractRunner;
  }

Description An options object type used by createEthersContract function. It can either provide a chainId if Tevm config has addresses for contracts configured for that chain or provide the address prop to specify the address directly. Both options require a runner property which is an Ethers.js provider or signer.

Params

  • chainId or address: You should provide either the chainId or the address of the contract. If you use the chainId option, Tevm should have the addresses for contracts configured for that chain. If you use the address option, specify the address directly.
  • runner: This is an Ethers.js provider or signer.

Example

const optionsWithChainId = { chainId: 1, runner: provider }; // Using chainId
const optionsWithAddress = { address: "0x1234...abcd", runner: provider }; // Using address

See also

ethers v6 docs

License 📄