unisat-dev-docs

Access a user’s accounts

Once the dApp successfully connects to the wallet, you can use the following method to obtain the wallet’s address and public key.

Method

getAccounts

unisat.getAccounts()

Get address of current account

Parameters

none

Returns

Example

try {
    let res = await window.unisat.getAccounts();
    console.log(res)
} catch (e) {
    console.log(e);
}

> ["tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz"]

Additional Note


getPublicKey

 unisat.getPublicKey()

Get publicKey of current account.

Parameters

none

Returns

Example

try {
    let res = await window.unisat.getPublicKey();
    console.log(res)
} catch (e) {
    console.log(e);
}

> 03cbaedc26f03fd3ba02fc936f338e980c9e2172c5e23128877ed46827e935296f

Additional Note


accountsChanged

unisat.on('accountsChanged', handler: (accounts: Array<string>) => void);
unisat.removeListener('accountsChanged', handler: (accounts: Array<string>) => void);

The accountsChanged will be emitted whenever the user’s exposed account address changes.