Bitcoin Integrations

The BitcoinProvider defined in Tomo Connect SDK contains all the necessary functions to interact with the Bitcoin chain. Core functions are:

Get Wallet Address

async getAddress(): Promise<string>

Get Wallet Public Key

async getPublicKeyHex(): Promise<string>

Change Address Type

// supported types are P2PKH, P2WPKH, P2TR, P2SH
changeAddressType(addressType: string)

Get All Wallet Types and Addreses

export interface AddressInfo {
  value: AddressType;
  label: string;
  name: string;
  displayName?: string;
  hdPath: string;
  address?: string;
}

export const addressInfos: AddressInfo[] = [
  {
    value: AddressType.P2PKH,
    label: "P2PKH",
    name: "Legacy (P2PKH)",
    displayName: "Legacy",
    hdPath: "m/44'/0'/0'/0",
  },
  {
    value: AddressType.P2WPKH,
    label: "P2WPKH",
    name: "Native Segwit (P2WPKH)",
    displayName: "Native Segwit",
    hdPath: "m/84'/0'/0'/0",
  },
  {
    value: AddressType.P2TR,
    label: "P2TR",
    name: "Taproot (P2TR)",
    displayName: "Taproot",
    hdPath: "m/86'/0'/0'/0",
  },
  {
    value: AddressType.P2SH_P2WPKH,
    label: "P2SH",
    name: "Nested Segwit (P2SH-P2WPKH)",
    displayName: "Nested Segwit",
    hdPath: "m/49'/0'/0'/0",
  }
];

async getAllAddresses(): Promise<AddressInfo[]>

Send Bitcoin

// send BTC and returns the tx hash
async sendBitcoin(to: string, satAmount: number): Promise<string>

Sign Psbt

async signPsbt(psbtHex: string): Promise<string>

Sign Message

async signMessageBIP322(message: string): Promise<string> 

Switch Network

export type Network = "mainnet" | "testnet" | "signet";

async switchNetwork(network: Network) 

Get Balance

async getBalance(): Promise<number>

Get Network Fees

export type Fee = {
  // description of this fee type
  desc: string
  // fee rate
  feeRate: number
  // fee type, slow, fast, avg
  title: string
}
export type Fees = {
  list: Fee[]
}

async getFeeRate(): Promise<Fees>

Get UTXOs

export interface UTXO {
  // hash of transaction that holds the UTXO
  txid: string;
  // index of the output in the transaction
  vout: number;
  // amount of satoshis the UTXO holds
  value: number;
  // the script that the UTXO contains
  scriptPubKey: string;
}

getUtxos(address: string, amount: number): Promise<UTXO[]>

Get Latest Height

getBTCTipHeight(): Promise<number>

Get inscription data

export interface Inscription {
  inscriptionNumber: number
  inscriptionId: string
  offset: number
  moved: boolean
  sequence: number
  isCursed: boolean
  isVindicate: boolean
  isBRC20: boolean
}
export interface UTXOInscription {
  // hash of transaction that holds the UTXO
  txid: string
  // index of the output in the transaction
  vout: number
  // amount in satoshi
  satoshi: number
  // the script that the UTXO contains
  scriptPk: string
  // address uxto belongs to
  address: string
  // inscription info
  inscriptions: Inscription[]
}
export interface InscriptionData {
  // hash of transaction that holds the UTXO
  data: {
    utxo: UTXOInscription[]
  };
  // index of the output in the transaction
  vout: number;
  // amount of satoshis the UTXO holds
  value: number;
  // the script that the UTXO contains
  scriptPubKey: string;
}
getInscriptionData(address: string, network: 'MAINNET'|'TESTNET'): Promise<InscriptionData>

Last updated