npm install web3 web3modal @coinbase/wallet-sdk @walletconnect/web3-provider fortmatic jsencrypt
//nftWeb3.js
import Web3 from 'web3' // "version": "1.2.9"
import Web3Modal from 'web3modal'
import Fortmatic from 'fortmatic'
import CoinbaseWalletSDK from '@coinbase/wallet-sdk'
import WalletConnectProvider from '@walletconnect/web3-provider'
//钱包配置项
const PROVIDER_OPTIONS = {
walletlink: {
package: CoinbaseWalletSDK, // Required
options: {
appName: 'NFTSTAR', // Required
infuraId: 'c353a2febff64ea38db941efdef9f6e6'
}
},
walletconnect: {
package: WalletConnectProvider,
options: {
// PANSHUO's test key
infuraId: 'c353a2febff64ea38db941efdef9f6e6',
qrcodeModalOptions: {
mobileLinks: [],
desktopLinks: []
}
}
},
fortmatic: {
package: Fortmatic,
options: {
// Mikko's TESTNET api key
key: 'pk_test_144C2F4E330A5997',
network: {
rpcUrl: 'https://rinkeby.infura.io/v3/c353a2febff64ea38db941efdef9f6e6',
chainId: 4
}
}
}
}
const connectWallet()=>{
const w3m = new Web3Modal({
theme: 'light',
cacheProvider: false,
providerOptions: PROVIDER_OPTIONS
})
const provider = await w3m.connect()
return provider
}
//调用nftWeb3.js
import Web3 from "web3";
import { connectWallet } from '@/nftWeb3'
methods:{
async handleWeb3LogIn(){
const provider= await connectWallet()
const web3 = new Web3(provider)
//拿到钱包地址
const accounts = await web3.eth.getAccounts()
}
}