Skip to main content

Enabling A Wallet

Overview

Before we can start interacting with a wallet, we will need ask the wallet to enable the dApp. This will achieve two things:

  • it will authorize your dApp with the wallet; and
  • it will get a list of the accounts available for your dApp to use.
note

It should be safe to call enable() as many times as your dApp wants, the wallet should assume this.

caution

The definition of "enabling" a wallet can mean different things to different wallets, but it is highly recommended that you first run enable() before attempting any other operations.

Enabling the default wallet

If you only want the default wallet, you can simply call:

try {
const result = await window.algorand.enable();

console.log(result);
/*
{
accounts: [
{
address: 'P3AIQVDJ2CTH54KSJE63YWB7IZGS4W4JGC53I6GK72BGZ5BXO2B2PS4M4U',
name: 'Wallet-1',
},
{
address: '6GT6EXFDAHZDZYUOPT725ZRWYBZDCEGYT7SYYXGJKRFUAG5B7JMI7DQRNQ',
name: 'Wallet-2',
},
],
genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=',
genesisId: 'mainnet-v1.0',
id: 'awesome-wallet',
sessionId: 'ab192498-0c63-4028-80fd-f148710611d8',
}
*/
} catch (error) {
// handle error
}
caution

If no wallets are found, then a NoWalletsDetectedError will be thrown.

Enabling a specific wallet

If you want to target a specific wallet, you can simply pass the ID of the wallet to the options object:

try {
const result = await window.algorand.enable({
id: 'another-awesome-wallet',
});

console.log(result);
/*
{
accounts: [
{
address: 'P3AIQVDJ2CTH54KSJE63YWB7IZGS4W4JGC53I6GK72BGZ5BXO2B2PS4M4U',
name: 'Wallet-1',
},
{
address: '6GT6EXFDAHZDZYUOPT725ZRWYBZDCEGYT7SYYXGJKRFUAG5B7JMI7DQRNQ',
name: 'Wallet-2',
},
],
genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=',
genesisId: 'mainnet-v1.0',
id: 'another-awesome-wallet',
sessionId: 'ab192498-0c63-4028-80fd-f148710611d8',
}
*/
} catch (error) {
// handle error
}
caution

If the specified wallet does not exist, then a WalletDoesNotExistError will be thrown.

Enabling a specific network

If you want to target a specific network, and the wallet supports it, you can simply pass the genesis hash of the network to the options object:

try {
const result = await window.algorand.enable({
genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=',
});

console.log(result);
/*
{
accounts: [
{
address: 'P3AIQVDJ2CTH54KSJE63YWB7IZGS4W4JGC53I6GK72BGZ5BXO2B2PS4M4U',
name: 'Wallet-1',
},
{
address: '6GT6EXFDAHZDZYUOPT725ZRWYBZDCEGYT7SYYXGJKRFUAG5B7JMI7DQRNQ',
name: 'Wallet-2',
},
],
genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=',
genesisId: 'testnet-v1.0',
id: 'awesome-wallet',
sessionId: 'ab192498-0c63-4028-80fd-f148710611d8',
}
*/
} catch (error) {
// handle error
}
caution

If the specified network is not supported, then a NetworkNotSupportedError will be thrown.