Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@delvtech/evm-client

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@delvtech/evm-client

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

npmnpm
Version
0.3.1
Version published
Maintainers
1
Created
Source

@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

FAQs

Package last updated on 03 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts