Skip to content

RPC Provider

Loop Decoder requires an RPC provider to fetch transaction data. To configure RPC providers, implement a getPublicClient function that returns a PublicClientObject based on the chain ID.

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))
}

Code Examples

  1. RPC Provider (Effect API) - Decoder API
  2. RPC Provider (Vanilla JS API) - Farcaster on-chain alerts bot

PublicClientObject Structure

The PublicClientObject consists of two properties:

client

config

An optional configuration object with the following properties:

  • traceAPI: Specifies the tracing API to use (default: parity)
    • parity - for Parity/OpenEthereum RPC nodes
    • geth - for Geth RPC nodes
    • none - when tracing is not supported