Connecting a web3 wallet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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