⛓ Establishing a Connection

BoltX injects a global API (window.boltX) into websites visited by users. This API allows websites to request access to user's BoltX addresses, read data from blockchains the user is connected to, and suggest that the user sign messages and transactions.

First and foremost, the application needs to be connected to the BoltX. BoltX has API in order to enable user connect to various blockchains: Ethereum, Zilliqa and Carbon(former Tradehub).

Sample code for Zilliqa:

  const boltX = (window as any).boltX; 
  if (typeof boltX === "undefined") throw new Error("BoltX extension not installed");
  const result = await boltX.zilliqa.wallet.connect();
  if (result !== boltX.zilliqa.wallet.isConnected)
    throw new Error("BoltX could not be connected to.");

Sample code for Ethereum:

if (typeof window.boltX === 'undefined') {
  console.log('Please install BoltX!');
}

const ethereum= await window.boltX.ethereum;

Sample code for Carbon(former Tradehub):

if (typeof window.boltX === 'undefined') {
  console.log('Please install BoltX!');
}

const tradehub = await window.boltX.tradehub;

await tradehub.connect();
// detect boltX

if (typeof window.boltX === 'undefined') {
  console.log('Please install BoltX!');
}

window.boltX.isBoltX // true
window.boltX.isConnected // true if active connection (refresh page if its false)

const handleConnectionChanged = (isConnected) => {
 if (!isConnected) {
  window.location.reload();
 }
}

/**
 * Note: 
 * window.boltX.events.CONNECTION_CHANGED === 'connectionChanged'
 */

window.boltX.on('connectionChanged', handleConnectionChanged );

Properties:

boltX.isBoltX

Note: Non-BoltX providers may also set this property to true.

  • true if the user has Bolt-X installed

boltX.isConnected

  • true if there is an active communication between extension and boltX

boltX.isUnlocked

  • true if the user's Bolt-X extension is unlocked

boltX.events

  • Mapping of events that are emitted by window.boltX

Methods:

boltX.connectAll()

  • connect to all Blockchains

  • (ie: request addresses for all supported blockchains)

return {
    hasZilWallet,
    hasEthWallet,
    hasBnbWallet,
    hasBtcWallet,
    hasSwthWallet,
};

Events

The boltX object inherits the eventEmitter methods and emits the following events.

connectionChanged

  • Emitted when isConnected changes

  • Useful for tracking when the wallet is connected to the website

  • Recommended action is to initiate a page refresh

unlockChanged

  • Emitted when isUnlocked changes

  • Useful for tracking when the wallet is locked and requires another call of connect methods to prompt the user to re-login.

  • Usage will be up to the developer's discretion

Blockchain

boltX.zilliqa

  • Same structure as @zilliqa-js

boltX.ethereum

  • Compliant to EIP-1193: Ethereum Provider JavaScript API

  • Compliant to EIP-695: Create `eth_chainId` method for JSON-RPC

  • Compliant to EIP-2696: JavaScript `request` method RPC transport

  • Compliant to EIP-2700: JavaScript Provider Event Emitter

boltX.tradehub

  • Similar to boltX.ethereum provider structure

  • boltX.tradehub.request makes requests using public endpoints

    • ie. no authentication

  • boltX.tradehub.sendTx makes requests using private endpoints

    • ie. with authentication

Last updated