Skip to content

Commit be1e8b5

Browse files
committed
Doc updates
1 parent 9fb5a45 commit be1e8b5

File tree

1 file changed

+104
-52
lines changed

1 file changed

+104
-52
lines changed

README.md

Lines changed: 104 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,149 @@
11
# Onboard
22

3-
Client library to onboard users to web3 apps
3+
JavaScript library to easily onboard users to ethereum apps by enabling wallet selection, connection and readiness and real time state updates.
44

5-
## Build
5+
## Install
66

7-
- Clone the repo
8-
- Run `npm install` to install dependencies
9-
- `npm run build`
7+
`npm install bnc-onboard`
108

11-
### Initialize
12-
13-
```javascript
14-
const onboard = Onboard({
15-
dappId: String, // Your api key - Head to https://www.blocknative.com/ to get a free key
16-
networkId: Number, // The id of the network your dapp runs on
17-
subscriptions: {
18-
address: Function, // called when address has changed
19-
network: Function, // called when network has changed
20-
balance: Function, // called when balance has changed
21-
provider: Function // called when provider has changed
22-
},
23-
modules: {
24-
selectWallet: {
25-
heading: String, // The heading for the select wallet modal
26-
description: String, // Description for the select wallet modal
27-
wallets: {
28-
mobile: Array, // Array of wallet modules for mobile devices
29-
desktop: Array // Array of wallet modules for desktop devices
30-
}
31-
},
32-
prepareWallet: Array // Array of onboarding modules
33-
}
34-
})
35-
```
36-
37-
#### Quick Start with Default Modules
9+
## Quick Start with Default Modules
3810

3911
```javascript
4012
import Onboard from 'bn-onboard'
41-
import { initModules as initWallets } from 'bn-wallet-modules'
42-
import { initModules as initOnboarding } from 'bn-onboarding-modules'
4313

44-
const onboard = Onboard({
14+
// initialize onboard
15+
const onboard = Onboard.init({
4516
dappId: 'Your apiKey here',
4617
networkId: 1,
4718
subscriptions: {
48-
address: address => console.log('address has changed:', address)
49-
network: network => console.log('network has changed:', network)
50-
balance: balance => console.log('balance has changed:', balance)
51-
provider: provider => console.log('provider has changed:', provider)
19+
address: address => console.log('user address has changed:', address)
20+
network: network => console.log('user network has changed:', network)
21+
balance: balance => console.log('user balance has changed:', balance)
22+
wallet: wallet => console.log('a new wallet has been selected by user', wallet.provider, wallet.name)
5223
},
5324
modules: {
54-
selectWallet: initWallets({
25+
// default wallets that are included: MetaMask, Dapper, Coinbase, Trust, WalletConnect
26+
walletSelect: Onboard.modules.select({
27+
// if you want fortmatic as a wallet option
5528
fortmaticInit: { apiKey: "Your fortmatic key here" },
29+
// if you want portis as a wallet option
5630
portisInit: { apiKey: "Your portis key here" },
5731
networkId: 4
5832
}),
59-
prepareWallet: initOnboarding({
33+
// default ready steps are: connect, network, balance
34+
walletReady: Onboard.modules.ready({
6035
networkId: 4,
6136
minimumBalance: "200000000000000000"
6237
})
6338
}
6439
})
40+
41+
// Get user to select a wallet
42+
await onboard.walletSelect()
43+
44+
// Get users' wallet ready to transact
45+
await onboard.walletReady()
6546
```
6647

67-
### Select Wallet
48+
## Initialization
49+
50+
```javascript
51+
const options = {
52+
dappId: "Your api key here"
53+
networkId: 4,
54+
subscriptions: {
55+
address: val => console.log("address", val)
56+
network: val => console.log("network", val)
57+
balance: val => console.log("balance", val)
58+
wallet: val => console.log("wallet", val)
59+
},
60+
modules: {
61+
walletSelect: {
62+
heading: "Select a Wallet"
63+
description: "Please select a wallet that you would like to use with this Dapp"
64+
wallets: {
65+
mobile: [mobileWalletModuleOne, mobileWalletModuleTwo, ...]
66+
desktop: [desktopWalletModuleOne, desktopWalletModuleTwo, desktopWalletModuleThree, ...]
67+
}
68+
},
69+
walletReady: [readyModuleStepOne, readyModuleStepTwo, readyModuleStepThree, ...]
70+
}
71+
}
72+
73+
const onboard = Onboard.init(options)
74+
```
75+
76+
### Options
77+
78+
```javascript
79+
const options = {
80+
dappId: String,
81+
networkId: Number,
82+
subscriptions: {
83+
address: Function, // Called with the current account address of the user [String]
84+
network: Function, // Called with the current network id the users' wallet is connected to [Number]
85+
balance: Function, // Called with the current balance in `wei` of the users' current account address [String]
86+
wallet: Function // Called with the users' current selected wallet [Object]: {provider: Object, name: String}
87+
},
88+
modules: {
89+
walletSelect: {
90+
heading: String,
91+
description: String,
92+
wallets: {
93+
mobile: Array,
94+
desktop: Array
95+
}
96+
},
97+
walletReady: Array
98+
}
99+
}
100+
```
101+
102+
#### `dappId` - [REQUIRED]
103+
104+
Your unique apiKey that identifies your application. You can generate a dappId by visiting the [Blocknative account page](https://account.blocknative.com/) and create a free account.
105+
106+
#### `networkId` - [REQUIRED]
107+
108+
The Ethereum network id that your application runs on. The following values are valid:
109+
110+
- `1` Main Network
111+
- `3` Ropsten Test Network
112+
- `4` Rinkeby Test Network
113+
- `5` Goerli Test Network
114+
- `42` Kovan Test Network
115+
116+
## API
117+
118+
### `walletSelect`
68119

69-
To get a user to select a wallet to use with your dapp call the `selectWallet` function:
120+
When you are ready to start onboarding a user, call the `walletSelect` function to prompt them to display the wallet select UI:
70121

71122
```javascript
72-
const walletSelected = await onboard.selectWallet()
123+
const walletSelected = await onboard.walletSelect()
124+
// returns a Promise that:
73125
// resolves with true if user selected a wallet and provider is good to go
74-
// resolves with false if user exited from select wallet modal
126+
// resolves with false if user exited from wallet select modal
75127
```
76128

77-
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 contracts.
129+
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.
78130

79-
### Prepare Wallet
131+
### `walletReady`
80132

81-
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 `prepareWallet` function:
133+
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:
82134

83135
```javascript
84-
const readyToTransact = await onboard.prepareWallet()
136+
const readyToTransact = await onboard.walletReady()
137+
// returns a Promise that:
85138
// resolves with true if user is ready to transact
86139
// resolves with false if user exited before completing all prepare wallet modules
87140
```
88141

89142
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.
90143

91-
### Config
144+
### `config`
92145

93-
You can update configuration parameters via the `config` function:
146+
You can update configuration parameters by passing a config object in to the `config` function:
94147

95148
```javascript
96149
onboard.config({ darkMode: true })
@@ -101,6 +154,5 @@ Available parameters that you can edit are:
101154
```javascript
102155
{
103156
darkMode: Boolean, // (default: false)
104-
networkId: Number // as set with initialization of onboard
105157
}
106158
```

0 commit comments

Comments
 (0)