Trezor钱包JS开发文档

getAccountInfo - 获取账户信息

获取指定账户的信息。

调用方法

ES6:

const result = await TrezorConnect.getAccountInfo(params);

CommonJS:

TrezorConnect.getAccountInfo(params).then(function(result) {

});

参数:

可选的公共参数。

使用路径:

  • path:BIP32路径,必须
  • coin:数字货币标识,字符串,必须

使用公钥:

  • xpub:账户的扩展公钥,字符串,必须
  • coin:数字货币标识,字符串,必须

使用自动发现:

执行BIP-0044账户自动发现,提交给用户一组账户进行选择。

  • coin:数字货币标识

示例代码

获取第一个比特币账户的信息:

TrezorConnect.getAccountInfo({
    path: "m/49'/0'/0'",
    coin: "btc",
});

使用公钥获取账户信息:

TrezorConnect.getAccountInfo({
    xpub: "xpub6CVKsQYXc9awxgV1tWbG4foDvdcnieK2JkbpPEBKB5WwAPKBZ1mstLbKVB4ov7QzxzjaxNK6EfmNY5Jsk2cG26EVcEkycGW4tchT2dyUhrx",
    coin: "btc",
});

使用BIP-0044账户发现机制获取账户信息:

TrezorConnect.getAccountInfo({
    coin: "btc",
});

返回结果

{
    success: true,
    payload: {
        id: number,                           // account id
        path: Array<number>,                  // hardended path
        serializedPath: string,               // serialized path
        xpub: string,                         // public key
        address: string,                      // current address
        addressIndex: number,                 // current address index
        addressPath: Array<number>,           // hardended address path
        addressSerializedPath: Array<number>, // serialized address path
        balance: number,                      // account balance (including unconfirmed transactions)
        confirmed: number,                    // account confirmed balance
        transactions: number,                 // transactions count
        utxo: Array<Utxo>,                    // unspent outputs [detail](../../src/js/types/response.js#L57)
        usedAddresses: Array<{ address: string, received: number }>, // used addresses with received amount
        unusedAddresses: Array<string>,       // unused addresses
    }
}

错误信息:

{
    success: false,
    payload: {
        error: string // error message
    }
}

从之前版本迁移

v4及更早版本:

TrezorConnect.getAccountInfo("m/49'/0'/0'", function(result) {
    result.id               // not changed
    result.serializedPath   // not changed
    result.path             // not changed
    result.xpub             // not changed
    result.freshAddress     // renamed to "address"
    result.freshAddressPath // renamed to "addressPath"
    result.freshAddressId   // renamed to "addressIndex"
    result.serializedFreshAddressPath // renamed to "addressSerializedPath"
    result.balance   // not changed
    result.confirmed // not changed

});

应当是:

// params are key-value pairs inside Object
TrezorConnect.composeTransaction({ 
    path: "m/49'/0'/0'",
    coin: "btc"
}).then(function(result) {
    ...
})