Getting Started
Requirements
- TypeScript 5.x
exactOptionalPropertyTypes
andstrict
enabled in your tsconfig.json
Dependencies
To get started, install the package from npm, along with its peer dependencies:
Quick Start
To begin using the Loop Decoder, you need to create an instance of the LoopDecoder class. At a minimum, you must provide three data loaders:
getPublicClient
: This function returns an object with ViemPublicClient
based on the chain ID.
contractMetaStore
: This object has two required properties,get
andset
, which return and cache contract meta-information. Optionally, you can provide a list ofstrategies
that will resolve data when it is missing in the cache. See theContractData
type for the required properties of the contract meta-information.
abiStore
: Similarly, this object has two required properties,get
andset
, which return and cache the contract or fragment ABI based on the chain ID, address, function, or event signature. Additionally, it includes strategies to resolve the data from third parties when it is missing in the cache.
In the following example we will cache all types of ABIs into the same Map.
Finally, you can create a new instance of the LoopDecoder class:
It’s important to note that the Loop Decoder does not enforce any specific data source, allowing users of the library to load contract data as they see fit. Depending on the requirements of your application, you can either include the necessary data directly in your code for a small number of contracts or use a database as a cache.
LoopDecoder instances provide a public method, decodeTransaction
, which fetches and decodes a given transaction: