我正在尝试使用web3modal和walletconnect获得一个React。
在Metamask浏览器中,我在BSC上的dapp工作,但是在Safari (MacOs和iOS)上,我显示web3modal,用户给TrustWallet权限(例如),但是返回到Safari,站点不会获得帐户,什么都不能工作。
这是我的密码:
const providerOptions = {
walletconnect: {
package: WalletConnectProvider,
options: {
rpc: {
56: "https://bsc-dataseed.binance.org/"
}
},
network: 'binance'
}
};
const web3Modal = new Web3Modal({
cacheProvider: true,
providerOptions
});
const provider = await web3Modal.connect();
const web3 = new Web3(provider);在这一点上,当我试图通过以下方式获得帐户时:
const accounts = await web3.eth.getAccounts();我得到:
Unhandled Promise Rejection: Error: Failed to get accounts在控制台中,有很多对呋喃的调用,我无法理解,如果使用平衡计分卡(或者下一个问题:f如何配置呋喃以实现这一点),我为什么需要使用呋喃。
谢谢
发布于 2021-07-15 11:18:49
我建议您使用莫拉利斯。它有用酷钩反应的SDK。它还支持不同的提供者(walletconnect,元问询,.)。看看莫拉利斯反应。它拥有BSC、ETH和马季奇网络的快速节点。
获取用户钱包地址的示例:
import React from "react";
import { useMoralis } from "react-moralis";
function App() {
const { authenticate, isAuthenticated, user } = useMoralis();
if (!isAuthenticated) {
return (
<div>
<button onClick={() => authenticate()}>Authenticate</button>
</div>
);
}
return (
<div>
<h1>Welcome {user.attributes.ethAddress}</h1>
</div>
);
}https://ethereum.stackexchange.com/questions/103017
复制相似问题