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_bitcoinGet 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.
Get the public key
In addition to the address, you can get the concrete public key from the provider.
Switch Network
We support three networks for different purposes:
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.
Currently, the bip32-simple type does not support taproot addresses. Please select other address types when you need to sign a message with bip322-simple.
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.
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.
Last updated