Skip to content

Latest commit

 

History

History
94 lines (73 loc) · 1.91 KB

File metadata and controls

94 lines (73 loc) · 1.91 KB

Examples

Reading Blockchain Data

Get Balance

import { getBalance } from '@bigmi/core'

async function checkBalance(address: string) {
  const balance = await getBalance(client, { address })
  console.log('Balance:', balance)
}

Get Transaction

import { getTransaction } from '@bigmi/core'

async function getTx(txId: string) {
  const tx = await getTransaction(client, { txId })
  console.log('Transaction:', tx)
}

Get Block Information

import { getBlockCount } from '@bigmi/core'

async function getBlockInfo() {
  const blockCount = await getBlockCount(client)
  console.log('Current block:', blockCount)
}

Sending Transactions

Basic Transaction

import { sendUTXOTransaction } from '@bigmi/core'

async function sendTx(hex: string) {
  try {
    const txId = await sendUTXOTransaction(client, { hex })
    console.log('Transaction sent:', txId)
  } catch (error) {
    console.error('Transaction failed:', error)
  }
}

Wait for Confirmation

import { waitForTransaction } from '@bigmi/core'

async function waitForTx(txId: string, txHex: string) {
  const tx = await waitForTransaction(client, {
    txId,
    txHex,
    onReplaced: (response) => {
      console.log('Transaction replaced:', response.reason)
    },
  })
  console.log('Transaction confirmed:', tx)
}

Transaction Handling

import { sendUTXOTransaction, waitForTransaction } from '@bigmi/core'

async function sendAndWait(txHex: string) {
  try {
    const txId = await sendUTXOTransaction(client, { hex: txHex })
    const tx = await waitForTransaction(client, {
      txId,
      txHex,
      onReplaced: (response) => {
        console.log('Transaction replaced:', response.reason)
      },
    })
    console.log('Transaction confirmed:', tx)
  } catch (error) {
    console.error('Error:', error)
  }
}

⬅️ back