0.0.1-rc.6 • Published 1 year ago
@kodex-data/abi-tools v0.0.1-rc.6
@kodex-data/abi-tools
The @kodex-data/abi-tools
package provides several functions and types related to the Ethereum ABI (Application Binary Interface) specification.
Installation
To use @kodex-data/abi-tools
, simply run the following command:
yarn add @kodex-data/abi-tools
or
npm install @kodex-data/abi-tools
Usage
You can import the package and use the exported functions and types as follows:
import { isAbi, isAbiItem, validators, toSha256Hex } from '@kodex-data/abi-tools'
The following is a list of exported items:
isAbi
,isAbiItem
,isFragmentItem
, andisFragmentArray
: These are functions that check if the given input is a valid Ethereum ABI, ABI item, ABI fragment item, or an array of ABI fragment items respectively.validators
: An object that contains several validation functions and regular expressions used to validate various types of input, including integers, bytes, and arrays of bytes. These functions are used internally by the other exported functions.toSha256Hex(str: string): string
: A function that takes a string input, computes its SHA-256 hash, and returns it as a hexadecimal string.abiToFnName(abi: AbiItem): string
: A function that takes an ABI item object and returns the name of the corresponding function, if it exists.typeToString(input: AbiInput): string
: A function that takes an ABI input object and returns a string representation of its type.abiToName(abi: AbiItem): string
: A function that takes an ABI item object and returns a string representation of its function name, if it exists.abiToSig(abi: AbiItem, with0x?: boolean): string
: A function that takes an ABI item object and returns its 4-byte function signature as a hexadecimal string, with an optionalwith0x
parameter indicating whether or not to include the "0x" prefix.toFragment(abi: AbiItem): Fragments
: A function that takes an ABI item object and returns a detailed ABI fragment object.fromFragment(fragments: Fragments): AbiItem
: A function that takes an ABI fragment object and returns the corresponding ABI item object.toFragmentArray(abis: AbiItem[]): Fragments[]
: A function that takes an array of ABI item objects and returns an array of corresponding ABI fragment objects.toFragmentMap(abiItems: AbiItem[]): Map<string, Fragments>
: A function that takes an array of ABI item objects and returns a map object where the keys are function names and the values are corresponding ABI fragment objects.ItemIO
: A type that represents the input and output types for an ABI item.