Bitcoin
Bitcoin DApp 与 imToken 钱包交互开发者文档
钱包 Provider 注入
window.bitcoin = new BitcoinProvider({
requestTransport: ({ method, params }) => window.imToken.callApi(
'bitcoin.request',
{
method,
params
}
)
})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 transacion
* @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
请求用户账户
获取当前网络
获取公钥
获取余额
获取未花费交易 UTXO
签名 PSBT
批量签名 PSBT
签名消息
发送签名结果
切换网络
其他方法
获取钱包名称和 icon
事件监听
版本兼容
Last updated