Ebakus Web Wallet Loader

The wallet library creates an iframe and loads the web wallet library in there. It can accept custom configurations for the wallet (i.e. load custom tokens) and act as an interface between the dApp and the web wallet iframe. This way a user can use his wallet to interface with any ebakus dApp she wants without having to create new keys and manage multiple accounts, by sharing the same wallet when running in the same browser.

Safari browser: Sharing the same wallet accross dApps is not supported (using its default settings).

You can check how it looks like inside an existing dApp.

The boilerplate

The best way to start is to use the dApp Boilerplate, where you can see how you can use the wallet loader library to programatically:

  • Send transactions
  • Deploy contracts
  • Interact with smart contracts
  • Configure custom tokens

Contact us at hello@ebakus.com.

Have fun!

Load package

Using npm

npm install --save ebakus-web-wallet-loader

and use it like:

import ebakusWallet from 'ebakus-web-wallet-loader'

ebakusWallet.sendTransaction(...)

With a script tag from your site

In your dApp page you have to include our Wallet Loader script.

Load it from CDN:

<script src="https://unpkg.com/ebakus-web-wallet-loader" />

or copy it to your site:

<script src="./dist/wallet-loader.min.js" />

The script will expose window.ebakusWallet. You can also have a look at the example page.

API

The dApp can communicate with the wallet through the loader API.

Events

ebakusLoaded

When loader has finished loading with the wallet loading it will dispatch the ebakusLoaded event.

window.addEventListener(
  'ebakusLoaded',
  ev => {
    console.warn('Ebakus Wallet loaded')
  },
  false
)

ebakusCurrentProviderEndpoint

Every time the user switches the connected node the wallet will dispatch the ebakusCurrentProviderEndpoint event.

window.addEventListener(
  'ebakusCurrentProviderEndpoint',
  ({ detail: endpoint }) => {
    console.log('The web3 provider wallet is connected is:', endpoint)

    // for a new web3 instance
    web3 = Web3Ebakus(new Web3(endpoint))

    // or for using an existing one
    // web3.setProvider(endpoint)
  },
  false
)

ebakusConnectionStatus

Every time the wallet connection with the node changes it will dispatch the ebakusConnectionStatus event.

window.addEventListener(
  'ebakusConnectionStatus',
  ({ detail: connectionStatus }) => {
    console.warn('The wallet connection status changed to', connectionStatus)
  },
  false
)

ebakusBalance

On wallet balance change it will dispatch the ebakusBalance event.

window.addEventListener(
  'ebakusBalance',
  ({ detail: balance }) => {
    console.warn('The new user balance is', web3.utils.toWei(balance))
  },
  false
)

Methods

ebakusWallet.init(options)

The init method can be used in order to pass custom configuration for the actual wallet. At the moment, dApp is allowed to set custom tokens.

window.addEventListener(
  'ebakusLoaded',
  ev => {
    console.warn('Ebakus Wallet loaded')

    // loading custom token to wallet
    ebakusWallet.init({
      tokens: [
        {
          contract_address: '0xa679d48c57320e9f0eadb043c3ea3f8dcd97ed01',
          symbol: 'SIM',
          decimals: 18,
        },
      ],
    })
  },
  false
)

ebakusWallet.isWalletFrameLoaded()

The isWalletFrameLoaded method returns if the wallet frame has finished loading.

if (ebakusWallet.isWalletFrameLoaded()) {
  // do something
}

ebakusWallet.getCurrentProviderEndpoint()

The getCurrentProviderEndpoint method returns the wallet used web3 endpoint so as the dApp can connect to the same provider.

ebakusWallet.getCurrentProviderEndpoint().then(endpoint => {
  console.log('The web3 provider wallet is connected is:', endpoint)

  // for a new web3 instance
  web3 = Web3Ebakus(new Web3(endpoint))

  // or for using an existing one
  // web3.setProvider(endpoint)
})

ebakusWallet.unlockWallet()

The unlockWallet method will ask your user to unlock the wallet in case it is locked. This is not needed most times as the wallet will ask on the first wallet interaction, when needed.

ebakusWallet.unlockWallet()

ebakusWallet.getDefaultAddress()

The getDefaultAddress method returns the wallet address.

ebakusWallet.getDefaultAddress().then(address => {
  console.log('Your wallet address is:', address)
})

ebakusWallet.getBalance()

The getBalance method returns the wallet balance.

ebakusWallet.getBalance().then(balance => console.log)

ebakusWallet.sendTransaction(tx)

The sendTransaction method will ask user to confirm, sign and send the transaction at the network through the wallet.

ebakusWallet.sendTransaction(/* tx object */).then(receipt => console.log)

Development

Install dependencies

npm install

Compile for development (with hot-reload support)

npm start

Compile and minify for production

npm run build

Last update: 1 hour ago