Decoding Transaction with SQLite Data Store
Loop Decoder provides a built-in SQL Data Stores that can be used out of the box. The key benefits of using the built-in SQL stores are:
- You don’t need to write your own database schema,
get
orset
methods for the Data Stores. - You will get enhanced performance for decoding transactions by caching the data in the persistent storage.
- You can use any database supported by
@effect/sql
.
To use the built-in SQL stores you can import SqlAbiStore
and SqlContractMetaStore
from the @3loop/transaction-decoder/sql
.
Example
In this example we will use a Sqlite client for bun: SqliteClient
from @effect/sql-sqlite-bun
package.
The example implements a CLI that will use Sqlite
as a cache for the ABIs and Contract Metadata stores. It will decode any transaction by chain ID and transaction hash. The more its is used the more data will be cached in the database, thus making it faster to decode transactions.
Installation
You can add it directly into your project or create a new one.
Then install the necessary dependencies:
Setup Loop Decoder
Create a index.ts
file with the following content:
Run the script
Now you can run this script with bun: