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.
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))}
import { createPublicClient, http } from 'viem'
// Create a public client for the Ethereum Mainnet networkconst getPublicClient = (chainId: number) => { return { client: createPublicClient({ transport: http('https://rpc.ankr.com/eth'), }), }}
Code Examples
- RPC Provider (Effect API) - Decoder API
- RPC Provider (Vanilla JS API) - Farcaster on-chain alerts bot
PublicClientObject Structure
The PublicClientObject
consists of two properties:
client
- An instance of Viem’s
PublicClient
- See the Viem documentation for more details
config
An optional configuration object with the following properties:
traceAPI
: Specifies the tracing API to use (default:parity
)parity
- for Parity/OpenEthereum RPC nodesgeth
- for Geth RPC nodesnone
- when tracing is not supported