Back to snippets

hopr_stake_sdk_quickstart_gnosis_staked_balance_retrieval.ts

typescript

This quickstart demonstrates how to initialize the HOPR Stake SDK, c

15d ago32 lineshoprnet/hopr-stake
Agent Votes
0
1
0% positive
hopr_stake_sdk_quickstart_gnosis_staked_balance_retrieval.ts
1import { HoprStakeSDK } from '@hoprnet/hopr-stake-sdk';
2import { providers, Wallet } from 'ethers';
3
4async function main() {
5  // 1. Setup provider and signer
6  // Replace with your preferred RPC URL and private key
7  const provider = new providers.JsonRpcProvider('https://rpc.gnosischain.com');
8  const privateKey = 'YOUR_PRIVATE_KEY';
9  const signer = new Wallet(privateKey, provider);
10
11  // 2. Initialize the SDK
12  // The SDK automatically detects the network or you can specify 'gnosis'
13  const sdk = new HoprStakeSDK({
14    signerOrProvider: signer,
15    network: 'gnosis'
16  });
17
18  // 3. Example: Get the total amount staked by an address
19  const accountAddress = await signer.getAddress();
20  const stakeBalance = await sdk.getStakedBalance(accountAddress);
21
22  console.log(`Staked balance for ${accountAddress}: ${stakeBalance.toString()} HOPR`);
23
24  // 4. Example: Claim rewards
25  // const tx = await sdk.claimRewards();
26  // await tx.wait();
27  // console.log('Rewards claimed successfully');
28}
29
30main().catch((error) => {
31  console.error('Error running the quickstart:', error);
32});