@web3-onboard/web3auth
Wallet module for connecting Web3auth to web3-onboard
Install
npm i @web3-onboard/core @web3-onboard/web3auth
Options
See the Web3auth Docs for the extensive list of options.
For troubleshooting web3Auth errors, framework, polyfill, etc please see the official Web3Auth troubleshooting docs.
Usage
import Onboard from '@web3-onboard/core'
import web3authModule from '@web3-onboard/web3auth'
import { EthereumPrivateKeyProvider } from '@web3auth/ethereum-provider'
import { CHAIN_NAMESPACES } from '@web3auth/base'
const privateKeyProvider = new EthereumPrivateKeyProvider({
config: {
chainConfig: {
chainId: `0xAA36A7`,
rpcTarget: `https://rpc.sepolia.org/`,
chainNamespace: CHAIN_NAMESPACES.EIP155,
displayName: 'Sepolia',
blockExplorerUrl: 'https://sepolia.etherscan.io',
ticker: 'ETH',
tickerName: 'Ether',
logo: 'https://images.toruswallet.io/ethereum.svg'
}
}
})
const web3auth = web3authModule({
clientId:
'BErDmyuxFPtpvM_Isiy8RHNWOWYvkAUehrgmO0rDoe5yr33ixt5s98eT_qePTyRsgpN7SVQwrEUMx7gON0jBDQI',
privateKeyProvider: privateKeyProvider,
web3AuthNetwork: 'sapphire_devnet'
})
const onboard = Onboard({
wallets: [
web3auth
]
})
const connectedWallets = await onboard.connectWallet()
console.log(connectedWallets)
Types
import type { Web3AuthOptions, ModalConfig } from '@web3auth/modal'
import type { CustomChainConfig, OPENLOGIN_NETWORK_TYPE } from '@web3auth/base'
type Web3AuthModuleOptions = Omit<Web3AuthOptions, 'chainConfig'> & {
chainConfig?: Partial<CustomChainConfig> &
Pick<CustomChainConfig, 'chainNamespace'>
modalConfig?: Record<string, ModalConfig> | undefined
web3AuthNetwork: OPENLOGIN_NETWORK_TYPE
loginModalZIndex?: string
}
interface Web3AuthOptions extends Web3AuthNoModalOptions {
authMode?: 'DAPP' | 'WALLET'
uiConfig?: Omit<UIConfig, 'adapterListener'>
}
interface UIConfig {
appName?: string
appLogo?: string
theme?: 'light' | 'dark' | 'auto'
loginMethodsOrder?: string[]
defaultLanguage?: string
modalZIndex?: string
displayErrorsOnModal?: boolean
loginGridCol?: 2 | 3
primaryButton?: 'externalLogin' | 'socialLogin' | 'emailLogin'
adapterListener: SafeEventEmitter
web3AuthNetwork?: OPENLOGIN_NETWORK_TYPE
}
Build Environments
For troubleshooting web3Auth build env troubleshooting please also see the official Web3Auth troubleshooting docs.
Webpack 4
Node built-ins are automatically bundled in v4 so that portion is handled automatically.
web3auth will require a Babel to compile from es6 if not already supported. See config for Babel and Webpack4 as follows
npm i --save-dev @babel/cli @babel/core @babel/node @babel/plugin-proposal-nullish-coalescing-operator @babel/plugin-proposal-optional-chaining @babel/plugin-syntax-bigint @babel/register
AND
npm i babel-loader
babel.config.js
module.exports = api => {
api.cache(true)
const plugins = [
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-nullish-coalescing-operator',
'@babel/plugin-syntax-bigint'
]
return { plugins }
}
webpack.config.js
config.module.rules = [
...otherModuleRules,
{
test: /\.js$/,
exclude: _ => !/node_modules\/(@web3auth|@ethereumjs)/.test(_),
loader: 'babel-loader'
}
]