Tomo Docs
Tomo Docs
  • Overview
    • Introducing Tomo
    • Tomo's Key Management
  • Tomo SDK
    • TomoEVMKit
      • Quick Start
      • Use with Ethers.js
      • Migration from RainbowKit
      • Migration from Blocknative
      • Internal Wallet Services
      • Supported Chains
    • Tomo Web SDK
      • Quick Start
      • Solana Provider
      • EVM Provider
      • Bitcoin Provider
      • Tron Provider
      • Movement Provider
      • Sui Provider
      • Internal Wallet Services
    • Tomo Telegram SDK
      • Quick Start
      • Wallet Provider
        • EVM Provider
        • Solana Provider
        • Sui Provider (Beta)
        • TON Provider
      • Partners
    • Tomo Enterprise SDK
      • For Babylon
        • Install the SDK
        • Tomo Wallet Provider
        • Bitcoin Provider
        • Cosmos Provider
        • Multiple Connection Mode
        • Integrate Extension Wallet
          • Submit Wallet PR
          • Extend the SDK
          • Q & A
        • Integrate Mobile Wallet
  • TOMO WALLET
    • Tomo Wallets
    • Mobile Wallet
      • Tomo Keys
        • Bonding Curve Explained
        • How to: Tomo Keys
      • TomoID
        • How to: TomoID
        • How to: Connect Instagram
      • Tomo Socials
      • Tomo Android App
      • Tomo iOS App
    • Extension Wallet
      • Developer Manual
        • EVM Integration
        • Bitcoin Integration
      • Example of User Flows
        • Claiming Signet BTC
        • Staking at Testnet
      • Install Link
    • Telegram Wallet
      • Quick Start
      • Chains/Networks
      • User Manual
        • Account Security
        • Gift feature
        • FAQ
        • Transaction
        • Swap
  • ABOUT US
    • Brand Assets
    • Privacy Policy
Powered by GitBook
On this page
  • Get Address and Balance
  • Get the public key
  • Switch Network
  • Provider Functions
  • Signing a Message
  • Sign Psbt
  • Send Bitcoin
  1. Tomo SDK
  2. Tomo Web SDK

Bitcoin Provider

After setting up your wallet, you can have access to the Bitcoin provider:

// react
const { providers } = useTomo()
const { bitcoinProvider } = providers;

// pure js
const bitcoinProvider = window.tomo_bitcoin

Get Address and Balance

You can first check and change the address type you want to use

// interface
getAddressType(): string
changeAddressType(addressType: string): Promise<void>

export enum AddressType {
  P2PKH,
  P2WPKH,
  P2TR,
  P2SH_P2WPKH,
}

// react
const btcAddressType= await bitcoinProvider.getAddressType()
await bitcoinProvider.changeAddressType("P2SH_P2WPKH")

// pure js
const btcAddress = await window.tomo_bitcoin.getAddressType()
await window.tomo_bitcoin.changeAddressType("P2PKH")

Then, get the address. However, if the user uses extension wallet, not all address type may have value.

// interface
// get current type address, by default it is taproot
getAddress(): Promise<string>
getAllAddresses(): Promise<AddressInfo[]>
getBalance(address?: string): Promise<number>

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

// form wallet state
const { walletState, providers } = useTomo()
const { btcAddress } = walletState

// or 
const { bitcoinProvider } = providers;
const btcAddress = await bitcoinProvider.getAddress()
const allAddresses= await bitcoinProvider.getAllAddresses()
const balance= await bitcoinProvider.getBalance(btcAddress)

// pure js
const btcAddress = await window.tomo_bitcoin.getAddress()
const allAddresses= await window.tomo_bitcoin.getAllAddresses()
const balance= await window.tomo_bitcoin.getBalance(btcAddress)

Get the public key

In addition to the address, you can get the concrete public key from the provider.

//interface 
getPublicKey(): Promise<string>

//react
const publicKey = await bitcoinProvider.getPublicKey()

// pure js

const publicKey = await window.tomo_bitcoin.getPublicKey()

Switch Network

We support three networks for different purposes:

// interface
getNetwork(): string
switchNetwork(network: Network): Promise<void>
const network = 'signet' | 'testnet' | 'mainnet'

// react
const current = await bitcoinProvider.getNetwork()
const sendRes = await bitcoinProvider.switchNetwork(network)

// pure js
const current = await window.tomo_bitcoin.getNetwork()
const sendRes = await window.tomo_bitcoin.switchNetwork(network)

Provider Functions

providers.bitcoinProvider exposes three functions for sending requests to the user's wallet:

Signing a Message

It uses the bitcoinprovider to sign a plaintext offchain message, which returns the message's signature.

// interface
signMessage(message: string, _type: "ecdsa" | "bip322-simple" = "ecdsa"): Promise<string>

const message = 'your message'
const type: "ecdsa" | "bip322-simple" = 'ecdsa'   // default is ecdsa
// react
const signedMessage = await bitcoinProvider.signMessage(message, type)

// pure js
const signedMessage = window.tomo_bitcoin.signMessage(message, type)

Sign Psbt

Given a hex raw transaction you can use signPsbtmethod to get the signed transaction in hex value if the user approves the request.

// interface
signPsbt(psbtHex: string): Promise<string>
signPsbts(psbtHexs: string[]): Promise<string[]>


const psbtHex = 'hex String'

// react
const signed = await bitcoinProvider.signPsbt(psbtHex)

// pure js
const signed = await window.tomo_bitcoin.signPsbt(psbtHex)

Send Bitcoin

You can also send the transaction directly through this sendBitcoin method. The return value is the transaction signature if signed and sent correctly.

const toAddress = 'toAddress'
const satAmount = 1 // BTC
const feeRate = 123 // sat/vB


// react
const sendRes = await bitcoinProvider.sendBitcoin(toAddress, satAmount, feeRate)

// pure js
const sendRes = await  window.tomo_bitcoin.sendBitcoin(toAddress, satAmount, feeRate)
PreviousEVM ProviderNextTron Provider

Last updated 24 days ago