🇺🇲
Broearn Wallet Documentation
  • 🧬OVERVIEW
    • 💡What is Broearn Wallet?
    • 🛡️Security
    • 📋Available Networks
      • Parallel Universe Chain
      • Bitcoin
      • Ethereum
      • BNB Chain
      • Tron
      • Solana
      • OKX Chain
      • Optimism
      • Fantom
      • Ethereum Classic
      • Polygon
      • Avalanche
  • 🛸PUT
    • Extension & in Broearn app
      • Events
        • Disconnect
        • Accounts Changed
    • Detecting the Provider
  • Establishing a Connection
  • PROVIDER METHODS
    • Connect
    • Disconnect
    • SignMessage
    • SignTransaction
    • SignAllTransactions
    • SignAndSendTransaction
  • 🔹ETHEREUM & EVM
    • Getting Started with Ethereum and EVM
    • Detecting the Provider
    • Establishing a Connection
    • Sending a Transaction
    • Signing a Message
    • Provider API Reference
      • Properties
        • eth_chainId
        • eth_networkVersion
        • eth_selectedAddress
        • _events
        • _eventsCount
      • Events
        • Connect
        • Accounts Changed
        • Disconnect
        • Chain Changed
      • Methods
        • isConnected
        • request
  • Demo Applications
  • 📜ERRORS
  • ADVANCED
    • Auth
      • Web Javascript demo
      • Web Java
      • Web Golang
      • Web PHP
  • COMMUNITY AND SUPPORT
    • 🐦Twitter
    • ✈️Telegram
    • 🎮Discord
Powered by GitBook
On this page
  • Connecting
  • Disconnecting
  • Changing Accounts

Establishing a Connection

PreviousDetecting the ProviderNextPROVIDER METHODS

Last updated 1 year ago

Once an application has , 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 or .

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

The connect() call will return a 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 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: '' });
provider.request({ method: "disconnect", params: { 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}`);
});
detected the provider
signing a message
sending a transaction
Promise
Errors