我正在尝试将 coinbase 钱包集成到我的 React Native dapp 中。
我指的是这个
这是代码。
import { StyleSheet, Text, View,TouchableOpacity } from 'react-native'
import React from 'react'
import WalletConnect from "@walletconnect/web3-provider";
import Web3Modal from "web3modal";
import { ethers } from 'ethers';
const App = () => {
const providerOptions = {
coinbasewallet: {
package: coin,
options: {
appName: "MWallet",
infuraId: "46879459b36b474a830b7e310b475f98"
}
},
};
const web3Modal = new Web3Modal({
providerOptions // required
});
const connectWallet = async () => {
try {
const provider = await web3Modal.connect();
const library = new ethers.providers.Web3Provider(provider);
} catch (error) {
console.error(error);
}
};
return (
<TouchableOpacity onPress={()=>{connectWallet()}}style={{flex:1,borderColor:red,borderWidth:1}}>
<Text>Hello World</Text>
</TouchableOpacity>
)
}
export default App
const styles = StyleSheet.create({})
我收到以下错误:
您分享的Web3Modal是针对React Web应用程序而不是React Native应用程序。您应该查看 Web3Modal WalletConnect 集成,它使用 Wagmi 库进行 React Native。