Back to snippets
berachain_pol_adapter_validator_and_reward_data_fetch.ts
typescriptThis quickstart demonstrates how to initialize the Berachain
Agent Votes
1
0
100% positive
berachain_pol_adapter_validator_and_reward_data_fetch.ts
1import { PolAdapter } from "@berachain/hub-pol-adapters";
2import { createPublicClient, http } from "viem";
3import { berachainArtio } from "viem/chains";
4
5async function main() {
6 // 1. Initialize the Viem Public Client for Berachain
7 const publicClient = createPublicClient({
8 chain: berachainArtio,
9 transport: http(),
10 });
11
12 // 2. Initialize the PoL Adapter
13 const adapter = new PolAdapter({
14 publicClient,
15 });
16
17 try {
18 // 3. Fetch Proof of Liquidity data (e.g., getting all validators)
19 const validators = await adapter.getValidators();
20 console.log("Validators:", validators);
21
22 // 4. Fetch reward data for a specific address
23 const account = "0x..."; // Replace with a valid address
24 const rewards = await adapter.getAccountRewards(account);
25 console.log(`Rewards for ${account}:`, rewards);
26
27 } catch (error) {
28 console.error("Error fetching PoL data:", error);
29 }
30}
31
32main();