Onboard (older version)
This page is for Onboard v1, which is an older version. For web3-onboard which is the newest, modernized version, see the web3-onboard page.
Use the latest version of Onboard at https://github.com/blocknative/web3-onboard . This version is no longer maintained.
See our Migration guide here to migrate to web3-onboard from the older version
Quickstart
It should take less than 5 minutes to get going with Blocknative Onboard.
Create a Blocknative Account
Go to the Account Dashboard at https://explorer.blocknative.com/account and setup an account with an email address. You will receive an email to confirm your account.
Create your API Key
On the Account Dashboard at https://explorer.blocknative.com/account, create an API key with your choice of name or use/rename the Default Key. Consider using different API keys for development, staging, and production releases.
Install the widget using npm
Initialize the Library
Use the minimum required config. There are more options available as detailed in the initialization section.
The wallet subscription function will be called when the user selects a wallet so you can instantiate web3 with the selected provider.
Onboard User
Ask the user to select a wallet and then check wallet is ready to transact.
And you are live!
Screencasts
See the above Quickstart guide in a screencast:
For a deeper dive with additional wallets that builds on the Quick Start, see this screencast:
Example Code
For an example of a basic React demo integration of both Onboard.js and Notify.js, checkout the GitHub repo: https://github.com/blocknative/onboard-notify-react
and the live demo:
https://reactdemo.blocknative.com/
Initialization
Options
dappId
- [optional]
dappId
- [optional]Your unique apiKey
that identifies your application. You can generate a dappId
by visiting the Blocknative account page and create a free account. The dappid
enables Onboard to use Blocknative notification services to efficiently maintain address balance state. This is not required to use Onboard to connect wallets to Dapps. It is required to efficiently get an up to date wallet balance value via the balance
subscription or getState()
calls.
Efficiently getting an up to date wallet balance value is subject to our API Rate Limits.
networkId
- [required]
networkId
- [required]The Ethereum
network id that your application runs on. The following values are valid:
1
main
Ethereum Network mainnet3
ropsten
Ethereum Network testnet4
rinkeby
Ethereum Network testnet5
goerli
Ethereum Network testnet28
boba-rinkeby
Boba Network Rinkeby testnet42
kovan
Ethereum Network testnet56
bsc
Binance Smart Chain Network mainnet100
xdai
xDai POA Network mainnet137
polygon
Polygon-Matic Network mainnet250
fantom-opera
Fantom Network mainnet288
boba
Boba Network mainnet4000
fantom-testnet
Fantom Network testnet
networkName
- [optional]
networkName
- [optional]This option allows one to specify a custom network name for all non-supported networks (see networkId
above for supported networks). For instance, if you set networkId: 56
for Binance smart chain and the user is connected to a different network, the wallet select modal will show local as the network to switch to. But if you specify networkName: "Binance Mainnet"
then this will display instead of local.
darkMode
- [optional] - Default: false
darkMode
- [optional] - Default: false
Opt for the Dark color scheme or not.
blockPollingInterval
- [optional] - Default: 4000
blockPollingInterval
- [optional] - Default: 4000
Change the rate at which blocks are polled by provider, default is set to 4 seconds.
hideBranding
- [optional]
hideBranding
- [optional]If no dappId
is provided, then "Powered by Blocknative" branding will be displayed on all modals. You can choose to hide the branding by setting hideBranding: true
. If you have included a dappId
then the branding will be hidden by default. If you would like the branding to display when including a dappId
then set hideBranding: false
.
subscriptions
- [optional]
subscriptions
- [optional]An object of callback functions that get called whenever the corresponding value changes. Use these callbacks to sync your UI or to store the values for use elsewhere in your code. Valid parameters to register callbacks for are:
address
- called with the user's current address[string]
ens
- called with the user's current ens name (if available)[object]
name
- The user's resolved ens name[string]
avatar
- A link to the user's avatar[string]
getText
- A function to retrieve the user's text records[function]
contentHash
- The user's content hash record[string]
network
- called with the user's current network id[number]
balance
- called with the user's current balance[string]
wallet
- called with the user's current wallet[object]
provider
- The JavaScript provider for interacting with the walletname
- The wallet display nameinstance
- If the wallet type is'sdk'
then this is the initialized wallet instancetype
- The wallet type'hardware' | 'injected' | 'sdk'
connect
- The function that initiates the wallet connection logicdashboard
- Some SDK wallets allow for opening to wallet dashboardicons
-[object]
Image strings for the wallet icon{ svg, src, srcset }
** walletSelect
- [optional]**
walletSelect
- [optional]**A object that defines how the wallet select screen will render using the following parameters:
heading
- [optional] : A string that will be the wallet select modal headingdescription
- [optional] : A string that will be the wallet select modal descriptionexplanation
- [optional] : A string that will be included in the "What is a Wallet" sectionwallets
- [optional] : An array of wallet modules or wallet initialization objects that the user can select fromagreement
- [optional]: An object containing properties for use with terms of service agreementversion
- The current version of the terms that the user needs to agree to. When this value is updated the user's agreement is invalidated and they must re-agree upon next usage.termsUrl
- [optional]: A string that will be used for the terms of service url that a user can agree to before using onboardprivacyUrl
- [optional]: A string that will be used for the privacy policy url that a user can agree to before using onboard
If not provided, then the default heading
and description
and wallets
that don't require initialization will be included for you.
walletCheck
- [optional]
walletCheck
- [optional]An array of wallet check modules or wallet check initialization objects that will be used to check if the user is ready to transact.
Initialize Onboard
To initialize Onboard, simply import the library and call it with your initializationOptions
:
The return value will be the initialized onboard
library which contains the API functions below.
Customizing 'unknown' Network Name
If you initialize Onboard with a networkId
that is not one of the supported networks all modals will refer to that network with the name unknown
. You can name unrecognized networks by also passing in a networkName
in to your initialization object:
Local Networks
If you are using a local network for testing, you can ensure that the onboarding checks work correctly by setting the networkId
for that local network to a number that is not taken by other valid networks.
If you are using the ganache-cli
for instance, you can set the networkId
via the -i
flag:
This will set the Ganache networkId
to 35
Then in your Onboard config, also set the networkId
property to the same value:
API
walletSelect
walletSelect
When you are ready to get a user to select a wallet and connect it to your Dapp, you can call the walletSelect
function to display the wallet select modal:
This function will show a modal that displays buttons for all of the wallets that you initialized onboard with. It will guide the user through the process of connecting to the wallet that they select. Once the process is successful the function will resolve with true
. This means that the provider
subscription will have been called with the provider of the selected wallet and you can go ahead and instantiate your web3 library with the provider and also instantiate your contracts.
The walletSelect
function can also be called with a autoSelectWallet
string. If the string passed in is a valid walletName
, then Onboard will automatically select that wallet for the user. This enables saving the previously selected wallet in localStorage
and automatically selecting it for the user when they next visit your Dapp.
walletCheck
walletCheck
Once a wallet is selected, you will want to make sure that the user's wallet is prepared and ready to transact by calling the walletCheck
function:
This function will run through the walletCheck
modules that were passed in via initialization sequentially, making sure the user has passed the condition contained in each module and eventually resolves with true
if the user completed the sequence. This means that the user is ready to transact. This function is useful to call before every transaction to make sure that nothing has changed since the last time it was called.
walletReset
walletReset
You may want to reset all of Onboard's internal wallet state and also disconnect from any active SDK instances when a user logs out of your app. You can call the walletReset
function to do this easily.
accountSelect
accountSelect
If you want to show the account select modal for hardware wallets at any time you can call the accountSelect
function. For example you could display a button that allows the user switch accounts:
getState
getState
This function will give you the current state of the user:
config
config
You can update some configuration parameters by passing a config
object in to the config
function:
Available parameters that you can update are:
darkMode
-[boolean]
networkId
-[number]
Built-in Modules
Wallet Modules
Initialization:
To initialize the built in wallet modules, an array of wallet initialization objects needs to be passed to the walletSelect.wallets
parameter of the Onboard initialization object. The order of the array is the order that the wallets will be displayed. Mobile wallets will be displayed when a user is on a mobile device and desktop wallets are displayed when they are on a desktop device.
Each wallet initialization object has additional optional customization parameters:
preferred
-Boolean
Will define whether it is shown at the top of the selection screen. If any of the wallets are set topreferred
, then all other wallets that aren't, will be hidden until the user clicks the "Show More" button. If there are no wallets set topreferred
, then the first four wallets will be shown and the remaining wallets will be hidden until the show more button is clicked.label
-String
Will over ride the wallet name that is displayed on the button.svg
-String
Ansvg
string that will over ride the icon that is displayed on the button.iconSrc
-String
An alternative to providing thesvg
string, by providing a url source.display
-Object
Customize which wallets to display based on which device a user is using. Note: For wallets that are mobile or desktop only this option will not override this. For instance, if a wallet is mobile only setting
display: { desktop: true }
will not display this wallet on desktop.desktop
-Boolean
default:true
mobile
-Boolean
default:true
An example configuration that includes all of the supported wallets:
The following list of wallet modules are included in Onboard and their initializationObject
is listed for each wallet:
Wallets
detectedwallet
The detected wallet will be displayed as an option when an injected Ethereum provider is detected, but it is not recognized by Onboard. This allows users to connect to your app with any provider that conforms to the EIP-1193 standard.
metamask - (desktop & mobile support)
authereum - (desktop & mobile support)
walletConnect - (desktop & mobile support)
portis - (desktop & mobile support)
fortmatic - (desktop & mobile support)
trust - (mobile only support)
coinbase - (mobile only support)
Desktop support for``
Coinbase Wallet
``can be found through``
walletLink module
opera - (desktop & mobile support)
opera touch - (mobile only support)
status - (mobile only support)
torus - (desktop & mobile support)
For additional details on the Torus options, check out their docs
trezor - (desktop & mobile support)
Trezor requires extra details such as appUrl
and email
for their manifest
ledger - (desktop & mobile support)
Ledger has an additional optional LedgerTransport
parameter for when you are building an Electron app and need to pass in the node ledger transport module. You can also use this option to pass in whichever Ledger transport that you would like to use based on feature detection (eg. Windows 10 user might need WebUSB transport instead of the default U2F transport).
lattice - (desktop & mobile support)
keepkey - (desktop only support)
cobovault - (desktop & mobile support)
keystone - (desktop & mobile support)
walletLink -``
Coinbase Wallet
``for desktop (desktop only support)
imToken - (mobile only support)
meetone - (mobile only support)
mykey - (mobile only support)
huobiwallet - (mobile only support)
hyperpay - (mobile only support)
wallet.io - (mobile only support)
atoken - (mobile only support)
frame - (mobile only support)
ownbit - (mobile only support)
alphawallet - (mobile only support)
gnosis - (desktop only support)
Gnosis wallet is unique as it designed to be used within the Gnosis Safe Apps interface. If the user opens your dApp within the Safe Apps interface, Gnosis wallet will be automatically selected and the select wallet modal will not be shown. This is to ensure that the user doesn't mistakenly use their wallet instead of their Safe Multisig wallet for the transaction.
xdefi - (desktop & mobile support)
bitpie - (mobile only support)
liquality - (desktop only support)
binance - (desktop only support)
mewwallet - (mobile only support)
tally - (desktop only support)
blankwallet - (desktop only support)
mathwallet - (desktop & mobile support)
1inch - (mobile only support)
Did - (mobile only support)
ronin - (desktop only support)
Ronin now only works on Axie's domains and will open to be used by other domains when the Ronin chain is ready - Updates From Ronin Dev
Due to the Ronin extension restriction, please add 127.0.0.1 dev.skymavis.one
in your hosts file /etc/hosts
and access dev.skymavis.one:<port>
instead of localhost:<port>
.
Hardware Wallet Custom Networks
Onboard now supports passing in custom network info for hardware wallets allowing users to use their hardware wallets with non-Ethereum networks such as Energy Web Chain. The customNetwork
object is passed to the Common
constructor of the @ethereumjs/common
library. This is then used to build the transaction that will be signed. Please refer to these instructions for more information.
Note: Currently only Trezor and Ledger support this functionality/
Example
You can view an example configuration here.
Wallet Check Modules
Initialization:
To initialize the built in wallet check modules, an array of wallet check initialization objects needs to be passed to the walletCheck
parameter of the Onboard initialization object. The order of the array is the order that the checks will be performed.
Each wallet check initialization object has additional optional customization parameters:
heading
-String
Will over ride the heading displayed in the wallet check modal.description
-String
Will over ride the description displayed in the wallet check modal.icon
-String
Ansvg
string that will over ride the icon displayed in the wallet check modal.button
-{ text: String, onclick: () => void}
An object that defines an extra button's text and onclick function.html
-String
A html string that will be rendered in the modal as html markup underneath the description.
The following wallet check modules are included in Onboard:
connect
: Checks that the Dapp has access to the users' accounts and fires the connect function if the selected wallet has one to prompt the user to allow access.
derivationPath
: Provides a UI to allow a user to select or input the derivation path they would like to use with their hardware wallet. Note: will only display if the connected wallet is of type "hardware". Note:html
andbutton
customization parameters won't work for this module as it needs them itself for correct operation.
accounts
: Provides a UI to allow a user to select and load accounts on their hardware wallet. Note: will only display if the connected wallet is of type "hardware". Note:html
andbutton
customization parameters won't work for this module as it needs them itself for correct operation.
network
: Checks that the users' wallet is connected to the network that the modules were initialized with.
balance
: Checks that the users' account has the minimum balance as defined when initialized.
In order for Onboard to efficiently detect wallet balance changes, a dappId
is required when initializing Onboard. This feature is subject to our API Rate Limits.
Creating Custom Modules
Onboard has been built so that custom wallet and wallet check modules can be plugged in to allow for the breadth of different wallets and on-boarding flows that are needed across the web3 ecosystem.
Custom Wallet Modules
A wallet module is an abstraction that allows interoperability between wallets within Onboard.
A wallet module has the following properties:
name
- [string][required]
name
- [string][required]
The name of the wallet.
wallet
- [function][required]
wallet
- [function][required]
A function that is called when this wallet is selected. It is called with a helpers
object that includes some helper functions that make it easier to create the return object. The helpers
object contains the following methods:
getProviderName
- A function that takes a provider as an argument and will return the name of the most common providers.createLegacyProviderInterface
- A function that takes the provider as an argument and returns awalletInterface
. Legacy refers to a provider that has not implementedEIP-1102
.createModernProviderInterface
- A function that takes the provider as an argument and returns awalletInterface
. Modern refers to a provider that has implementedEIP-1102
. This will work for most providers and is a quick way to create an interface.BigNumber
- Abignumber.js
function for number calculations.getNetwork
- A function that takes a provider and will make aJSON-RPC
call to get the network.getAddress
- A function that takes a provider and will make aJSON-RPC
call to get the address.getBalance
- A function that takes a provider and will make aJSON-RPC
call to get the balance.
The wallet
function must return a Promise
that resolves to an object that has the following properties:
provider
- the JavaScript provider for this wallet. [required]
instance
- for SDK
wallets instances that are separate from the provider
. [optional]
interface
- a walletInterface
or null
if the user's current provider is not this wallet (for extension and mobile wallets). [required]
walletInterface
An abstraction built on top of an Ethereum
JavaScript provider allowing interoperability with wallets and providers of any architecture. A valid walletInterface
implements the following methods and attributes:
name
- The name of the wallet. [string][required]
connect
- A function that requests account access and returns a Promise
that resolves or rejects once the user confirms or rejects the request. [function][optional]
disconnect
- A function to clean up / destroy any instances (mostly for SDK
wallets). Will be called when a new wallet has been selected. [function][optional]
loading
- A function that returns a Promise
that resolves when the wallet has finished loading. This is to show a loading spinner as the wallet popup is loading (mostly for SDK
wallets). [function][optional]
address
- A stateSyncer
object (see below for details). The get
function on this stateSyncer
must return a string which is the wallet address.
network
- A stateSyncer
object (see below for details). The get
function on this stateSyncer
must return a number which is the wallet network id.
balance
- A stateSyncer
object (see below for details). The get
function on this stateSyncer
must return a string which is the wallet address balance.
stateSyncer
An object that has either a get
function or a onChange
function and is used to keep user state in sync. The onChange
method is preferred as it doesn't require background polling to keep in sync.
The get
function returns a promise that resolves with a value.
The onChange
function takes a setState
function as an argument and is used to set the state. Often it is needed to use the setState
function to set the initial state and then register it to be called every time it changes.
iconSrc
- [string][optional]
iconSrc
- [string][optional]
A source for the wallet logo icon.
iconSrcSet
- [string][optional]
iconSrcSet
- [string][optional]
A source for the hi-res wallet logo icon.
svg
- **** [string][optional]
svg
- **** [string][optional]
A svg
element string for the wallet logo icon.
link
- [string][optional]
link
- [string][optional]
A link to install this wallet (extension and injected provider wallets).
installMessage
- [function][optional]
installMessage
- [function][optional]
A function that will be called when a user has selected this wallet, but the wallet
function did not return a wallet interface
. This is generally only needed if this wallet injects the provider via an extension or mobile wallet and the user doesn't have the extension installed or is on the wrong mobile browser. The function will be called with an object that has two properties: currentWallet
(the name of the wallet that has been detected by Onboard) and selectedWallet
(the name of the selected wallet), and must return a string (that can include html
) that instructs the user to install this wallet.
desktop
- [boolean][optional]
desktop
- [boolean][optional]
Whether the wallet is a desktop wallet or not.
mobile
- [boolean][optional]
mobile
- [boolean][optional]
Whether the wallet is a mobile wallet or not.
preferred
- [boolean][optional
preferred
- [boolean][optional
Whether this wallet will be displayed as a preferred wallet.
Example
Custom Wallet Check Modules
You can create custom onboarding flows by stringing together a sequence of wallet check modules that check that the users' state is correct before moving forward. A wallet check module is a function that gets called with an object which contains the users' current state and either returns a result of undefined
if that check has passed or a modalObject
if it failed. A wallet check module can also return a Promise
that resolves to the check result, allowing asynchronous actions and checks to be a part of your onboarding flow.
A wallet check module will be called with a state object with the following parameters and functions:
address
- The users' current address. [string]
network
- The users' current network id. [number]
balance
- The users' current account balance in wei
. [string]
appNetworkId
- The networkId
that the Dapp is configured to work with. [number]
wallet
- The users' wallet object containing the properties: provider
, interface
, connect
, name
, loading
and instance
. [object]
mobileDevice
- Whether the user is on a mobile device or not. [boolean]
BigNumber
- A bignumber.js
function for number calculations. [function]
walletSelect
- Call this to switch wallets, will close wallet check dialog and open wallet select dialog. [function]
exit
- Call to exit wallet check dialog. [function]
modalObject
modalObject
The module function then needs to evaluate a condition and then return a result of undefined
if the condition has been met or a modalObject
if not. The modalObject
is an object with the following properties:
heading
- The heading for the wallet check modal. [string][required]
description
- The description for the wallet check modal. [string][required]
eventCode
- An event code that is used for your back-end analytics dashboard. [string][required]
**button
** - **** A object with an onclick
property to register a function to run when the button is clicked, and a text
property for the button text [object][optional]
html
- A html string that will be rendered in the modal as html markup underneath the description [string][optional]
icon
- A icon to be displayed next to the heading. [string][optional]
action
- A function to run upon showing the modal that returns a Promise that resolves when finished or rejects with an error. [function][optional]
Example
For a user to interact with your Dapp, they may require a token balance (ie Dai
). You could build a module that checks that a user has the required token balance to continue:
Caching Wallet Selection
You may want to cache the wallet a user has selected previously so that you can automatically select it for them next time they visit your app for a silky smooth user experience. The first step is to store the wallet name in local storage when the user selects a wallet. You can do this by adding some code to your wallet subscription function inside the onboard config:
Then you can add code that runs when your app first load, that will retrieve the selectedWallet
value from localStorage
and then call walletSelect
with that value. Onboard will then automatically select it for the user if that wallet is available:
Adding Networks/Chains
Certain wallets give the option to add networks or chains from predefined configurations. This example will use MetaMask.
Once connected and a wallet provider
exposed the wallet_addEthereumChain
method can be called with specific configurations to setup that ethereum based chain within the wallet.
Once the network is setup within the wallet wallet_switchEthereumChain
can then be called to switch to chains that have been setup.
More info around these method calls can be found here
Customizing CSS
To gain the required specificity to override the default styles, you need to use the class name .bn-onboard-custom
plus the class name that you would like to override in your CSS
file. For example, if you would like to customize the font-family
for the onboard modals, then you would target the top level element that has the class .bn-onboard-modal
in your CSS
file:
Below is a list of the main classes that you can target to customize the CSS
:
.bn-onboard-modal
- The full page modal container.
.bn-onboard-modal-content
- The container for the modal content.
.bn-onboard-modal-header
- The header of the modal
.bn-onboard-modal-content-header-heading
- The heading within the header.
.bn-onboard-select-description
- The wallet select modal description.
.bn-onboard-modal-select-wallets
- The unordered list of wallets.
.bn-onboard-icon-button
- The wallet button.
.bn-onboard-modal-selected-wallet
- Selected wallet modal content.
.bn-onboard-prepare-button
- All modal buttons
The z-index
property for all Onboard modals was removed in version 1.9.6
to prevent interference with wallet modals. If you would like to restore the z-index
setting from previous versions then add the following to your CSS:
.bn-onboard-custom.bn-onboard-modal { z-index: 99; }
Get Started Today
Sign up for a free Blocknative Account at https://explorer.blocknative.com/account with your work email address.
If you have any questions, connect with the team on our discord
React Demo
To see an Onboard integration in a simple React app you can check out our react-demo
repo on GitHub: https://github.com/blocknative/react-demo
We have the reactdemo
codebase deployed so that you try Onboard from an end user perspective: https://reactdemo.blocknative.com/
Rollup Builds
For projects using Webpack for bundling, Onboard.js will work out of the box. If you are using Rollup as your bundler you will need to install some extra plugins and add some configurations to your rollup.config.js
file due to Rollup not including the node
built-in functions automatically. The script tag in your index.html
will also need to be modified to allow for code-splitting.
Ledger and Trezor wallets do not currently work in Rollup due to the lack of maintained support for node built-ins. To get your build to work you need to not include wallet initialization objects for those wallets in your Onboard config.
The plugins you will need to install as devDependencies
are:
The basic rollup.config.js
configuration looks like this:
In your index.html
you need to add type="module"
to the script tag that imports your bundle to enable code-splitting:
Last updated