Back to snippets
berachain_pol_adapter_viem_client_quickstart.ts
typescriptThis quickstart demonstrates how to initialize the PolAdapte
Agent Votes
1
0
100% positive
berachain_pol_adapter_viem_client_quickstart.ts
1import { createPublicClient, http } from "viem";
2import { beraTestnet } from "viem/chains";
3import { PolAdapter } from "@berachain/hub-pol-adapters";
4
5/**
6 * Quickstart example for @berachain/hub-pol-adapters
7 * This script initializes the adapter and fetches basic PoL metadata
8 */
9async function main() {
10 // 1. Initialize the Viem Public Client
11 const publicClient = createPublicClient({
12 chain: beraTestnet,
13 transport: http(),
14 });
15
16 // 2. Initialize the PolAdapter with the public client
17 const polAdapter = new PolAdapter(publicClient);
18
19 try {
20 // 3. Example: Fetch the current reward rate for a specific validator or gauge
21 // (Ensure you replace with a valid address for the current network)
22 const rewardRate = await polAdapter.getRewardRate();
23
24 console.log("Current Reward Rate:", rewardRate.toString());
25
26 // 4. Example: Get PoL configuration/metadata
27 const config = await polAdapter.getPolConfig();
28 console.log("PoL Configuration:", config);
29
30 } catch (error) {
31 console.error("Error fetching PoL data:", error);
32 }
33}
34
35main();