Getting Started
Try Loop Decoder
Requirements
- TypeScript 5.x
exactOptionalPropertyTypes
andstrict
enabled in yourtsconfig.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:
- RPC Provider
- ABI Loader
- Contract Meta Information Loader
Loop Decoder has default in-memory implementations for ABI and contract meta-information loaders: InMemoryAbiStoreLive
and InMemoryContractMetaStoreLive
. If you need more customization for a storage, see our guide on How To Decode Transaction.
getPublicClient
: This function returns an object with ViemPublicClient
based on the chain ID. For detailed configuration options and trace API settings, see the RPC Provider documentation.
-
abiStore
: To avoid making unecessary calls to third-party APIs, Loop Decoder uses an API that allows cache. For this example, we will keep it simple and use an in-memory cache. We will also use some strategies to download contract ABIs from Etherscan and 4byte.directory. You can find more information about the strategies in the Strategies reference. -
contractMetaStore
: Create an in-memory cache for contract meta-information. We will automatically retrieve ERC20, ERC721, and ERC1155 token meta information from the contract such as token name, decimals, symbol, etc.
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: