Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

Latest commit

 

History

History
126 lines (112 loc) · 4.22 KB

getAddress.md

File metadata and controls

126 lines (112 loc) · 4.22 KB

Get address

Display requested address derived by given BIP32 path on device and returns it to caller. User is asked to confirm the export on Trezor.

ES6

const result = await TrezorConnect.getAddress(params);

CommonJS

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

});

Params

Optional common params

Exporting single address

  • pathrequired string | Array<number> minimum length is 5. read more
  • addressoptional string address for validation (read Handle button request section below)
  • showOnTrezoroptional boolean determines if address will be displayed on device. Default is set to true
  • coin - optional string determines network definition specified in coins.json file. Coin shortcut, name or label can be used. If coin is not set API will try to get network definition from path.
  • crossChainoptional boolean Advanced feature. Use it only if you are know what you are doing. Allows to generate address between chains. For example Bitcoin path on Litecoin network will display cross chain address in Litecoin format.
  • multisig - optional MultisigRedeemScriptType, redeem script information (multisig addresses only)
  • scriptType - optional InputScriptType, address script type

Exporting bundle of addresses

  • bundle - Array of Objects with path, showOnTrezor, coin and crossChain fields

Handle button request

Since [email protected] there is a possibility to handle UI.ADDRESS_VALIDATION event which will be triggered once the address is displayed on the device. You can handle this event and display custom UI inside of your application.

If certain conditions are fulfilled popup will not be used at all:

  • the user gave permissions to communicate with Trezor
  • device is authenticated by pin/passphrase
  • application has TrezorConnect.on(UI.ADDRESS_VALIDATION, () => {}); listener registered
  • parameter address is set
  • parameter showOnTrezor is set to true (or not set at all)
  • application is requesting ONLY ONE(!) address

Example

Display third address of first bitcoin account:

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

Return a bundle of addresses from first bitcoin account without displaying them on device:

TrezorConnect.getAddress({
    bundle: [
        { path: "m/49'/0'/0'/0/0", showOnTrezor: false }, // address 1
        { path: "m/49'/0'/0'/0/1", showOnTrezor: false }, // address 2
        { path: "m/49'/0'/0'/0/2", showOnTrezor: false }  // address 3
    ]
});

Validate address using custom UI inside of your application:

import TrezorConnect, { UI } from 'trezor-connect';

TrezorConnect.on(UI.ADDRESS_VALIDATION, data => {
    console.log("Handle button request", data.address, data.serializedPath);
    // here you can display custom UI inside of your app
});

const result = await TrezorConnect.getAddress({
    path: "m/49'/0'/0'/0/0",
    address: "3L6TyTisPBmrDAj6RoKmDzNnj4eQi54gD2",
});
// dont forget to hide your custom UI after you get the result!

Result

Result with only one address

{
    success: true,
    payload: {
        address: string,     // displayed address
        path: Array<number>, // hardended path
        serializedPath: string,
    }
}

Result with bundle of addresses

{
    success: true,
    payload: [
        { address: string, path: Array<number>, serializedPath: string }, // address 1
        { address: string, path: Array<number>, serializedPath: string }, // address 2
        { address: string, path: Array<number>, serializedPath: string }, // address 3
    ]
}

Error

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

Migration from older version

v4 and below:

TrezorConnect.getAddress("m/49'/0'/4'/0/0", function(result) {
    // added "serializedPath" field
});

should be

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