DappAuth
A Plug-n-Play Javascript library for adding UI interface for onboarding users to ethereum(upcoming support for other blockchain platforms) apps by enabling wallet selection, connection, readiness and real time state updates.
Install
npm install dappauth
Quick Start with Default Modules
// initialize DappAuth modulesconst modules = DappAuth // initialize dappauthconst dappauth = DappAuth // Get user to select a walletawait dappauth // Get users' wallet ready to transactawait dappauth
Initialization
const options = networkId: 4 subscriptions: console console console console modules: walletSelect: heading: "Select a Wallet" description: "Please select a wallet that you would like to use with this Dapp" wallets: mobile: mobileWalletModuleOne mobileWalletModuleTwo ... desktop: desktopWalletModuleOne desktopWalletModuleTwo desktopWalletModuleThree ... walletReady: readyModuleStepOne readyModuleStepTwo readyModuleStepThree ... const dappauth = DappAuth
Options
const options = networkId: Number // see below subscriptions: address: Function // Called with the current account address of the user [String] network: Function // Called with the current network id the users' wallet is connected to [Number] balance: Function // Called with the current balance in `wei` of the users' current account address [String] wallet: Function // Called with the users' current selected wallet [Object]: {provider: Object, name: String, instance: Object (if a sdk wallet)} modules: walletSelect: heading: String // The heading for the wallet select modal description: String // The description for the wallet select modal wallets: mobile: Array // array of mobile wallet modules desktop: Array // array of desktop wallet modules walletReady: Array // array of wallet readiness modules
projectId
- [REQUIRED]
Your unique apiKey that identifies your application. You can generate a projectId by visiting the Dappkit account page and create a free account.
networkId
- [REQUIRED]
The Ethereum network id that your application runs on. The following values are valid:
1
Main Network3
Ropsten Test Network4
Rinkeby Test Network5
Goerli Test Network42
Kovan Test Network
API
walletSelect
When you are ready to start onboarding a user, call the walletSelect
function to prompt them to display the wallet select UI:
const walletSelected = await dappauth// returns a Promise that:// resolves with true if user selected a wallet and provider is good to go// resolves with false if user exited from wallet select modal
This function will show a modal that displays buttons for all of the wallets that you initialized dappauth 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.
walletReady
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 walletReady
function:
const readyToTransact = await dappauth// returns a Promise that:// resolves with true if user is ready to transact// resolves with false if user exited before completing all wallet readiness modules
This function will run through the onboarding modules 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.
config
You can update configuration parameters by passing a config object in to the config
function:
dappauth
Available parameters that you can edit are:
darkMode: Boolean // (default: false)
Modules
Wallet Select Modules
The wallet select modules are functions that return a wallet object. The following modules are currently available:
defaults
: A meta module that quickly initializes all of the default modules into the correct format (requires initialization object)
Desktop Wallets
metamask
dapper
torus
keybase
[COMING SOON]ledger
[COMING SOON]trezor
[COMING SOON]walletConnect
(requires initialization)portis
(requires initialization)squarelink
(requires initialization)fortmatic
(requires initialization)bitski
(requires initialization)[COMING SOON]uport
(requires initialization)[COMING SOON]
Mobile Wallets
trust
coinbase
torus
keybase
[COMING SOON]trezor
[COMING SOON]walletConnect
(requires initialization)portis
(requires initialization)squarelink
(requires initialization)fortmatic
(requires initialization)bitski
(requires initialization)[COMING SOON]uport
(requires initialization)[COMING SOON]
defaults
Initialization:
modulesselect
portis
Initialization:
squarelink
Initialization:
fortmatic
Initialization:
walletConnect
Initialization:
Example
// PICK AND CHOOSE MODULES const modules = Dappauth const portis squarelink dapper metamask fortmatic torus } = modulesselect const dappauth = DappAuth // OR // USE ALL OF THE DEFAULT MODULES const dappauth = DappAuth
Wallet Ready Modules
The wallet ready modules are functions that return a function that will be called with the current user state. The module will return a modal object if that state is invalid or undefined
if the state is valid. The following default modules are available:
defaults
: A meta module that quickly initializes all of the default modules into the correct format (requires initialization object)connect
: Checks that the dapp has access to accounts and fires the connect function if the selected wallet has onenetwork
: Checks that the users' wallet is connected to the desired network (requires initialization argument)balance
: Checks that the users' account has enough balance as defined when initialized (requires initialization argument)
defaults
Initialization:
modulesready
network
Initialization:
// the network id your dapp runs on
balance
Initialization:
// the minimum balance in wei required to interact with your dapp
Example
const modules = Dappauth // PICK AND CHOOSE MODULES const connect network balance = modulesready const dappauth = DappAuth // OR // USE ALL OF THE DEFAULT MODULES const dappauth = DappAuth