Bitcoin Provider
Using the BTC Provider API
Once you connect the wallet, you can use the following way to interact with the connected wallet:
import {
useTomoProviders,
useTomoModalControl,
useTomoWalletConnect,
useTomoWalletState,
useWalletList
} from '@tomo-inc/wallet-connect-sdk'
// Open BTC connection modal
const tomoModal = useTomoModalControl();
tomoModal.open("bitcoin");
// tomoModal.open('cosmos'); to open Cosmos wallets connection modal
// Check wallet connection status
const tomowalletState = useTomoWalletState();
const connected = tomowalletState.isConnected;
// Check all the supported wallets
const supportedWallets = useWalletList();
// Get provider
const providers = useTomoProviders();
const provider = providers.bitcoinProvider;
// Disconnect
const tomoWalletConnect = useTomoWalletConnect();
tomoWalletConnect.disconnect();
All the provider APIs are as follows:
export type Fees = {
// fee for inclusion in the next block
fastestFee: number
// fee for inclusion in a block in 30 mins
halfHourFee: number
// fee for inclusion in a block in 1 hour
hourFee: number
// economy fee: inclusion not guaranteed
economyFee: number
// minimum fee: the minimum fee of the network
minimumFee: number
}
// UTXO is a structure defining attributes for a UTXO
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
}
// supported networks
export enum Network {
MAINNET = 'mainnet',
TESTNET = 'testnet',
SIGNET = 'signet'
}
export interface InscriptionResult {
list: Inscription[]
total: number
}
export interface Inscription {
output: string
inscriptionId: string
address: string
offset: number
outputValue: number
location: string
contentType: string
contentLength: number
inscriptionNumber: number
timestamp: number
genesisTransaction: string
}
export abstract class BTCProvider extends WalletProvider {
abstract connectWallet(): Promise<this>
abstract getAddress(): Promise<string>
abstract getPublicKeyHex(): Promise<string>
abstract signPsbt(psbtHex: string): Promise<string>
abstract signPsbts(psbtsHexes: string[]): Promise<string[]>
abstract getNetwork(): Promise<Network>
abstract signMessage(message: string, type: type: 'ecdsa' | 'bip322-simple'): Promise<string>
abstract on(eventName: string, callBack: () => void): void
abstract off(eventName: string, callBack: () => void): void
abstract switchNetwork(network: Network): Promise<void>
abstract sendBitcoin(to: string, satAmount: number): Promise<string>
abstract getNetworkFees(): Promise<Fees>
abstract pushTx(txHex: string): Promise<string>
abstract getUtxos(address: string, amount?: number): Promise<UTXO[]>
abstract getBTCTipHeight(): Promise<number>
abstract getBalance(): Promise<number>
abstract getInscriptions(cursor?: number, size?: number): Promise<InscriptionResult>
}
Last updated