Bitcoin
Wallet Provider Injection
window.bitcoin = new BitcoinProvider({
requestTransport: ({ method, params }) => window.imToken.callApi(
'bitcoin.request',
{
method,
params
}
)
})Schema
type WalletRpcSchema = [
/**
* @description Requests that the user provides an address to be identified by.
* @example
* provider.request({ method: 'btc_requestAccounts' }] })
* // => ['tbc1...', 'tbc1...']
*/
{
Method: 'btc_requestAccounts'
Parameters?: undefined
ReturnType: string[]
},
/**
* @description Returns the current network associated with the wallet.
* @example
* provider.request({ method: 'btc_getNetwork' })
* // => 'signet'
*/
{
Method: 'btc_getNetwork'
Parameters?: undefined
ReturnType: Network
},
/**
* @description Gets the public key of the connected wallet.
* @example
* provider.request({ method: 'btc_getPublicKey' }] })
* // => 'publicKey...'
*/
{
Method: 'btc_getPublicKey'
Parameters?: undefined
ReturnType: string
},
/**
* @description Returns the balance of an address in satoshis.
* @example
* provider.request({ method: 'btc_getBalance', params: ['tbc1...'] })
* // => 1000
*/
{
Method: 'btc_getBalance'
Parameters: [address: string]
ReturnType: number
},
/**
* @description Retrieves the unspent transaction outputs (UTXOs) for a given address and amount.
* If the amount is provided, it will return UTXOs that cover the specified amount.
* If the amount is not provided, it will return all available UTXOs for the address.
* @example
* provider.request({ method: 'btc_getUnspent', params: ['tbc1...', 100] })
* // => [{ utxo }]
*/
{
Method: 'btc_getUnspent'
Parameters: [address: string, amount: number]
ReturnType: UTXO[]
},
/**
* @description Signs the given PSBT in hex format.
* @example
* provider.request({ method: 'btc_signPsbt', params: ['0x...', true] })
* // => '0x...'
*/
{
Method: 'btc_signPsbt'
Parameters: [psbtHex: Hex, autoFinalize?: boolean]
ReturnType: Hex
},
/**
* @description Signs multiple PSBTs in hex format.
* @example
* provider.request({ method: 'btc_signPsbts', params: ['0x...', '0x...'] })
* // => ['0x...', '0x...']
*/
{
Method: 'btc_signPsbts'
Parameters: [psbtsHexes: Hex[]]
ReturnType: Hex[]
},
/**
* @description Signs a message using BIP-322.
* @example
* provider.request({ method: 'btc_signMessage', params: ['tb1...'] })
* // => 'base64...'
*/
{
Method: 'btc_signMessage'
Parameters: [
message: string,
type: 'bip322-simple' | 'bip322-full' | 'bip322-legacy'
]
ReturnType: string
},
/**
* @description send raw transaction
* @example
* provider.request({ method: 'btc_sendRawTransaction', params: ['signature'] })
* // => 'string'
*/
{
Method: 'btc_sendRawTransaction'
Parameters: [signature: string]
ReturnType: string
},
/**
* @description Switch the wallet to the given network.
* @example
* provider.request({ method: 'btc_switchNetwork', params: ['signet'] })
* // => null
*/
{
Method: 'btc_switchNetwork'
Parameters: [network: Network]
ReturnType: null
}
]Provider API
Request User Accounts
Get Current Network
Get Public Key
Get Balance
Get Unspent Transaction Outputs (UTXO)
Sign PSBT
Batch Sign PSBT
Sign Message
Send Raw Transaction
Switch Network
Other Methods
Get Wallet Name and Icon
Event Listening
Version Compatibility
Last updated