Skip to content

Commit

Permalink
Update docs (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiarods authored Jan 14, 2025
1 parent 88bc99b commit 12b8e78
Show file tree
Hide file tree
Showing 17 changed files with 449 additions and 356 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```ts
export interface AbiStore<Key = AbiParams, Value = ContractAbiResult> {
readonly strategies: Record<ChainOrDefault, readonly ContractAbiResolverStrategy[]>
readonly set: (key: Key, value: Value) => Effect.Effect<void, never>
readonly get: (arg: Key) => Effect.Effect<Value, never>
readonly getMany?: (arg: Array<Key>) => Effect.Effect<Array<Value>, never>
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```ts
export interface ContractMetaStore<Key = ContractMetaParams, Value = ContractMetaResult> {
readonly strategies: Record<ChainOrDefault, readonly ContractMetaResolverStrategy[]>
readonly set: (arg: Key, value: Value) => Effect.Effect<void, never>
readonly get: (arg: Key) => Effect.Effect<Value, never>
readonly getMany?: (arg: Array<Key>) => Effect.Effect<Array<Value>, never>
}
```
15 changes: 15 additions & 0 deletions apps/docs/src/content/components/effect-rpc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```ts title="provider.ts"
import { PublicClient, PublicClientObject, UnknownNetwork } from '@3loop/transaction-decoder'
import { Effect } from 'effect'

const getPublicClient = (chainID: number): Effect.Effect<PublicClientObject, UnknownNetwork> => {
if (chainID === 1) {
return Effect.succeed({
client: createPublicClient({
transport: http('https://rpc.ankr.com/eth'),
}),
})
}
return Effect.fail(new UnknownNetwork(chainID))
}
```
2 changes: 1 addition & 1 deletion apps/docs/src/content/components/rpc-provider.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
```ts title="index.ts"
```ts title="provider.ts"
import { createPublicClient, http } from 'viem'

// Create a public client for the Ethereum Mainnet network
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Loop Decoder provides a `decodeCalldata` method that decodes a transaction calld

To use `decodeCalldata` method, you need to setup a `TransactionDecoder` instance with the necessary data stores. For setup instructions, refer to:

- Setup with default in-memory data stores (the quickest way): [Getting Started](/welcome/getting-started/)
- Setup with built-in in-memory data stores (the quickest way): [Getting Started](/welcome/getting-started/)
- Setup with customizable data stores: [How To Decode Transaction (detailed)](/guides/decode-transaction/)

### Decoding Calldata
Expand Down
8 changes: 5 additions & 3 deletions apps/docs/src/content/docs/guides/decode-transaction.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Decode an Ethereum Transaction (detailed)
title: Decoding Transaction
description: On this page you will provide a step-by-step guide on how to decode and interpret an Ethereum transaction using Loop Decoder.
sidebar:
order: 1
Expand All @@ -8,15 +8,17 @@ sidebar:
import { Content as MemoryAbiLoader } from '../../components/memory-abi-loader.md'
import { Content as MemoryContractLoader } from '../../components/memory-contract-loader.md'
import { Content as RpcProvider } from '../../components/rpc-provider.md'
import { Content as AbiStoreInterface } from '../../components/abi-store-interface.md'
import { Content as MetaStoreInterface } from '../../components/meta-store-interface.md'
import { Content as AbiStoreInterface } from '../../components/vanilla-abi-store-interface.md'
import { Content as MetaStoreInterface } from '../../components/vanilla-meta-store-interface.md'

This guide explains how to decode Ethereum transactions using Loop Decoder. We'll cover:

- Setting up data loading strategies for ABIs and contract metadata
- Configuring data stores for Contract ABIs and metadata
- Decoding transactions

[Learn more about Loop Decoder APIs and the differences between them](/reference/exposed-apis/)

## Installation

Generate and initialize a new project:
Expand Down
133 changes: 0 additions & 133 deletions apps/docs/src/content/docs/guides/effect-api.md

This file was deleted.

46 changes: 34 additions & 12 deletions apps/docs/src/content/docs/guides/sql-stores.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
---
title: SQL Data Store
title: Decoding Transaction with SQLite Data Store
description: An implementation of the Data Store interface using a SQL database based on @effect/sql
sidebar:
order: 4
order: 3
---

To use the default SQL stores you can import `SqlAbiStore` and `SqlContractMetaStore ` from the `@3loop/transaction-decoder/sql`.
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:

Given that the SQL stores are based on `@effect/sql` it inherits its SQL Client abstraction. For example we will use a Sqlite client for bun: `SqliteClient` from `@effect/sql-sqlite-bun` package.
- You don't need to write your own database schema, `get` or `set` methods for the [Data Stores](/reference/data-store).
- 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`](https://github.com/Effect-TS/effect/tree/main/packages/sql).

### Example
To use the built-in SQL stores you can import `SqlAbiStore` and `SqlContractMetaStore` from the `@3loop/transaction-decoder/sql`.

This 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 an transaction hash. The more its is used the more data will be cached in the database, thus making it faster to decode transactions.
## 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.

```shell
$ mkdir transaction-decoder-cli && cd transaction-decoder-cli && bun init
mkdir transaction-decoder-cli && cd transaction-decoder-cli && bun init
```

We will start by installing the necessary dependencies:
Then install the necessary dependencies:

```shell
$ bun i viem effect @effect/sql @effect/sql-sqlite-bun @3loop/transaction-decoder
bun i viem effect @effect/sql @effect/sql-sqlite-bun @3loop/transaction-decoder
```

Then we will create a `index.ts` file with the following content:
### Setup Loop Decoder

Create a `index.ts` file with the following content:

```typescript
import { SqlAbiStore, SqlContractMetaStore } from '@3loop/transaction-decoder/sql'
import {
decodeTransactionByHash,
ERC20RPCStrategyResolver,
EtherscanV2StrategyResolver,
FourByteStrategyResolver,
NFTRPCStrategyResolver,
PublicClient,
} from '@3loop/transaction-decoder'
import { SqliteClient } from '@effect/sql-sqlite-bun'
Expand Down Expand Up @@ -69,7 +81,15 @@ export const RPCProviderLive = Layer.succeed(
}),
)

const MetaStoreLive = SqlContractMetaStore.make()
const MetaStoreLive = Layer.unwrapEffect(
Effect.gen(function* () {
const service = yield* PublicClient

return SqlContractMetaStore.make({
default: [ERC20RPCStrategyResolver(service), NFTRPCStrategyResolver(service)],
})
}),
)
const DataLayer = Layer.mergeAll(RPCProviderLive, SqlLive)
const LoadersLayer = Layer.mergeAll(AbiStoreLive, MetaStoreLive)
const MainLayer = Layer.provideMerge(LoadersLayer, DataLayer)
Expand All @@ -90,8 +110,10 @@ function main() {
main()
```

### Run the script

Now you can run this script with bun:

```
$ ETHERSCAN_API_KEY='YOUR_API_KEY' RPC_1=https://rpc.ankr.com/eth bun run index.ts 1 0xc0bd04d7e94542e58709f51879f64946ff4a744e1c37f5f920cea3d478e115d7
ETHERSCAN_API_KEY='YOUR_API_KEY' RPC_1=https://rpc.ankr.com/eth bun run index.ts 1 0xc0bd04d7e94542e58709f51879f64946ff4a744e1c37f5f920cea3d478e115d7
```
35 changes: 0 additions & 35 deletions apps/docs/src/content/docs/reference/data-loaders.md

This file was deleted.

Loading

0 comments on commit 12b8e78

Please sign in to comment.