Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Connecting a web3 wallet
import { ethers } from 'ethers'
import Web3Modal from 'web3modal'
import WalletConnectProvider from '@walletconnect/web3-provider'
async function getWeb3Modal() {
const web3Modal = new Web3Modal({
network: 'mainnet',
cacheProvider: false,
providerOptions: {
walletconnect: {
package: WalletConnectProvider,
options: {
infuraId: YOUR_INFURA_ID
},
},
},
})
return web3Modal
}
/* invoke this function to prompt user and connect wallet */
async function connectWallet() {
const web3Modal = await getWeb3Modal()
const connection = await web3Modal.connect()
const provider = new ethers.providers.Web3Provider(connection)
const accounts = await provider.listAccounts()
console.log({ accounts })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment