Harmony Ethers.js Wrapper

Example: How to use provider to query Harmony chain

1
import {
2
Block,
3
BlockWithTransactions,
4
CXTransactionReceipt,
5
StakingTransactionResponse,
6
TransactionReceipt,
7
TransactionResponse,
8
} from "../src/types";
9
import { ApiHarmonyProvider } from "../src/provider";
10
11
// provider auto detects shard
12
const provider = new ApiHarmonyProvider("https://api.s0.b.hmny.io");
13
// to get block with harmony properties
14
const block: Block = await provider.getBlock(blockNumber || blockHash);
15
// to get block with transactions including staking transactions
16
const blockWithTransaction: BlockWithTransactions = await provider.getBlockWithTransactions(blockNumber || blockHash);
17
18
// get transaction / cx transaction
19
const tx: TransactionResponse = provider.getTransaction(txHash);
20
// get staking transaction
21
const sTx: StakingTransactionResponse = provider.getStakingTransaction(txHash);
22
23
// to get staking transaction recipt
24
const txReceipt: TransactionReceipt = provider.getTransactionReceipt(txHash);
25
26
// to get Cross Shard Receipt
27
const cTxReceipt: CXTransactionReceipt = provider.getCXTransactionReceipt(txHash);
Copied!
Last modified 4mo ago