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.
const result = await TrezorConnect.getAddress(params);
Params
Exporting single address
path
— requiredstring | Array<number>
minimum length is5
. read moreaddress
— optionalstring
address for validation (readHandle button request
section below)showOnTrezor
— optionalboolean
determines if address will be displayed on device. Default is set totrue
coin
- optionalstring
determines network definition specified in coins.json file. Coinshortcut
,name
orlabel
can be used. Ifcoin
is not set API will try to get network definition frompath
.crossChain
— optionalboolean
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 typeunlockPath
- optional PROTO.UnlockPath, the result of TrezorConnect.unlockPath method.chunkify
— optionalboolean
determines if address will be displayed in chunks of 4 characters. Default is set tofalse
Exporting bundle of addresses
bundle
-Array
of Objects withpath
,showOnTrezor
,coin
andcrossChain
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 totrue
(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
}
}