When asking for help in this category, please make sure to provide the following details:
- “@web3auth/no-modal”: “^8.12.4”,
- Nuxt
- Browser Console Screenshots:
I have a ethereum composable that generalizes some of the wallet connectors logic, so i created this connector for the Web3Auth, that’s how i am using:
import { Web3AuthNoModal } from '@web3auth/no-modal'
import { CHAIN_NAMESPACES, WALLET_ADAPTERS, WEB3AUTH_NETWORK } from '@web3auth/base'
import { EthereumPrivateKeyProvider } from '@web3auth/ethereum-provider'
import { WalletConnector, type ChainId, numberToHex, ChainIds } from '@ryze-blockchain/ethereum'
// import { BrowserProvider, JsonRpcProvider, Wallet } from 'ethers'
import { AuthAdapter } from '@web3auth/auth-adapter'
// import { CommonJRPCProvider } from '@web3auth/base-provider'
export class Web3AuthConnector extends WalletConnector {
public readonly id: string = 'web3auth'
public readonly name: string = 'Login with Google'
private chainConfig = {
chainNamespace: CHAIN_NAMESPACES.EIP155,
chainId: numberToHex(ChainIds.BNB_TESTNET),
rpcTarget: 'https://data-seed-prebsc-1-s1.binance.org:8545/',
displayName: 'Binance Smart Chain Testnet',
blockExplorerUrl: 'https://testnet.bscscan.com/',
ticker: 'BNB',
tickerName: 'Binance Coin',
logo: '/images/chains/binance.svg',
}
private clientId = 'BPS1KO7rAWwv_KdX9df1aMZFpCnJW4PgnpG0i2yGz9esEGoJLklJPveg02gampc_nr4_fR1pJJQZGOtlS22-jcA'
private static web3auth: Web3AuthNoModal
private static initialized = false
constructor() {
super()
const privateKeyProvider = new EthereumPrivateKeyProvider({
config: {
chainConfig: this.chainConfig,
},
})
Web3AuthConnector.web3auth = new Web3AuthNoModal({
clientId: this.clientId,
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_DEVNET,
privateKeyProvider,
})
Web3AuthConnector.web3auth.configureAdapter(new AuthAdapter({
privateKeyProvider,
}))
}
public async getProvider() {
console.log('Entered getProvider')
if (!Web3AuthConnector.initialized) {
Web3AuthConnector.initialized = true
await Web3AuthConnector.web3auth.init()
}
console.log('init done')
if (!Web3AuthConnector.web3auth.connected) {
await Web3AuthConnector.web3auth.connectTo(WALLET_ADAPTERS.AUTH, {
loginProvider: 'google',
})
}
console.log('here')
const web3authProvider = Web3AuthConnector.web3auth.provider
if (!web3authProvider)
throw new Error('Failed to connect to Web3Auth')
console.log('web3auth provider: ', web3authProvider)
return web3authProvider
}