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

@delvtech/evm-client

v0.5.1

Published

Useful EVM client abstractions for TypeScript projects that want to remain web3 library agnostic.

Downloads

497

Readme

@delvtech/evm-client

Useful EVM client abstractions for TypeScript projects that want to remain web3 library agnostic.

import {
  CachedReadWriteContract,
  ContractReadOptions,
} from '@delvtech/evm-client';
import erc20Abi from './abis/erc20Abi.json';

type CachedErc20Contract = CachedReadWriteContract<typeof erc20Abi>;

async function approve(
  contract: CachedErc20Contract,
  spender: `0x${string}`,
  amount: bigint,
) {
  const hash = await contract.write('approve', { spender, amount });

  this.contract.deleteRead('allowance', {
    owner: await contract.getSignerAddress(),
    spender,
  });

  return hash;
}

This project contains types that can be used in TypeScript projects that need to interact with contracts in a type-safe way based on ABIs. It allows your project to focus on core contract logic and remain flexible in it's implementation. To aid in implementation, this project provides:

  • Utility types
  • Utility functions for transforming arguments
  • Factories for wrapping contract instances with caching logic
  • Stubs to facilitate testing

Primary Abstractions

Contracts

The contract abstraction lets you write type-safe contract interactions that can be implemented in multiple web3 libraries and even multiple persistence layers. The API is meant to be easy to both read and write.

Types

  • ReadContract: A basic contract that can be used to fetch data, but can't submit transactions.
  • ReadWriteContract: An extended ReadContract that has a signer attached to it and can be used to submit transactions.
  • CachedReadContract: An extended ReadContract that will cache reads and event queries based on arguments with a few additional methods for interacting with the cache.
  • CachedReadWriteContract: An extended CachedReadContract that has a signer attached to it and can be used to submit transactions.

Utils

  • objectToArray: A function that takes an object of inputs (function and event arguments) and converts it into an array, ensuring parameters are properly ordered and the correct number of parameters are present.

  • arrayToObject: The opposite of objectToArray. A function to transform contract input and output arrays into objects.

  • arrayToFriendly: A function to transform contract output arrays into "Friendly" types. The friendly type of an output array depends on the number of output parameters:

    • Multiple parameters: An object with the argument names as keys (or their index if no name is found in the ABI) and the primitive type of the parameters as values.
    • Single parameters: The primitive type of the single parameter.
    • No parameters: undefined

Factories

Stubs

Network

The Network abstraction provides a small interface for fetching vital network information like blocks and transactions.

Types

Stubs

SimpleCache

A simple cache abstraction providing a minimal interface for facilitating contract caching.

Types

Utils

Factories