Bitcoin Provider (Beta)

The Tomo Telegram SDK provides a Bitcoin Provider for sending transactions. Below are methods that developers can use with our Bitcoin provider.

// get provider
const bitcoin = window.tg_tomo_btc;

Currently, Bitcoin provider supports the following address type

type BTCNetworkType = 'MAINNET' | 'TESTNET' | 'SIGNET';
type IBtcAddressType = 'bitcoinP2Wpkh' | 'bitcoinP2Sh' | 'bitcoinP2Tr' | 'bitcoinP2Pkh';
const btcAddressTypeMaps: IBtcAddressType[];

Connect with the Wallet

Before using the provider, the user needs to log in to the wallet through the modal by following the method:

// connect wallet
await bitcoin?.connectWallet();

Signing Methods

The Tomo Telegram SDK supports two signing methods:

  • btc_signMessage

  • btc_signTransaction

btc_signMessage method is used for siging a transaction that only record a message on-chain through OP_RETURN operation.

 const res = await bitcoin.request({
  method: 'btc_signMessage',
  params: [
    {
      addressType: btcAddressTypeMaps[2],
      message: 'btc sign message',
    },
  ],
});
    return res;

btc_signPsbt allows the user to sign a transaction with hex, and the return value is the signed transaction in hex.

 const res = await bitcoin.request({
  method: 'btc_signPsbt',
  params: [
    {
      network:'SIGNET',
      addressType: btcAddressTypeMaps[2],
      psbtHex: '0200000000010145430f279a5e63a9bda3761efbf9f49b9ee4d428f5fe4b2bfeae2e7b54ca83f90000000000fdffffff01bdd5070000000000160014a3213c72757d86a33543010ff748f203a544a2810247304402200134cddfacc47b1c84cd64c2f88d8aa0a3384f42c8ec659bb70dcc4ce4571b650220554c085d85aee0f09f45993dfd485d5ca3df3feba49f9195dfbc4e045694ee88012102d207a562f7466bd1be96be8b35c9ca481a907d8cbf4b1e131b072a4878c1178600000000'
    },
  ],
});
    return res;

Send Transaction

Using btc_sendTx , the developer can create a simple transfer transaction for the user to authorize and send to a specified network:

import { btcAddressTypeMaps } from 'tomo-tg-wallet-sdk';

const res = await bitcoin.request({
  method: 'btc_sendTx',
  params: [
    {
      network: 'SIGNET',
      addressType: btcAddressTypeMaps[2],
      toAddress: toAddr2,
      amount: toValue2,
    },
  ],
});

Last updated