Establishing a Connection

Once an application has detected the provider, it can then request to connect to Broearn Wallet. This connection request will prompt users for permission to share their public key, indicating that they are willing to interact further. Users must approve a connection request before the app can make additional requests such as signing a message or sending a transaction.

Once permission is established for the first time, the web application's domain will be whitelisted for future connection requests. After a connection is established, it is possible to terminate the connection from both the application and the user side.

Connecting

The recommended and easiest way to connect to Broearn Wallet is by calling window.bw.put.connect(). However, the provider also exposes a request JSON RPC interface.

const provider = getProvider(); // see "Detecting the Provider"
try {
    const resp = await provider.connect();
    console.log(resp.address);
    // 26qv4GCcx98RihuK3c4T6ozB3J7L6VwCuFVc7Ta2A3Uo 
} catch (err) {
    // { code: 4001, message: 'User rejected the request.' }
}

The connect() call will return a Promise that resolves when the user accepts the connection request, and reject (throw when awaited) when the user declines the request or closes the pop-up. See Errors for a breakdown of error messages Broearn Wallet may emit.

Disconnecting

Disconnecting mirrors the same process as connecting. However, it is also possible for the wallet to initiate disconnection, rather than the application itself.

provider.disconnect({ session: '' });

Changing Accounts

Broearn Wallet allows users to seamlessly manage multiple accounts from within a single extension or mobile app. Whenever a user switches accounts, Broearn Wallet will emit an accountChanged event.

If a user changes accounts while already connected to an application, and the new account has already whitelisted that application, then the user will stay connected and Broearn Wallet will pass the address of the new account:

provider.on('accountChanged', (addresses) => {
   console.log(`Switched to account ${addresses}`);
});

Last updated