连接到TrustWallet并获取BSC、ETH、BTC地址和余额 [英] connect to trustwallet and get bsc, eth, btc addresses and balances
本文介绍了连接到TrustWallet并获取BSC、ETH、BTC地址和余额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
但它只连接来自Trust Wallet的ETH地址
我尝试将提供程序选项更改为:
const providerOptions = {
walletconnect: {
package: WalletConnectProvider,
options: {
rpc: {
56: "https://bsc-dataseed.binance.org/"}
}
},
但不起作用
在我的信托钱包中,我有BTC地址、ETH地址、BNB地址,我想知道所有这些地址和余额。但是现在我只能得到这个地址我尝试过这样做:
const chainId = 56//await web3.eth.getChainId();
// Get list of accounts of the connected wallet
const accounts = await web3.eth.getAccounts();
但这只给我提供了ETH帐户。 那我该怎么办?
推荐答案
在我的案例中,它在Trust Wallet上工作,在Metamask移动应用程序上不工作:
walletconnect: {
package: WalletConnectProvider, // required
options: {
rpc: {
56: 'https://bsc-dataseed.binance.org/',
97: 'https://data-seed-prebsc-1-s1.binance.org:8545/',
},
network: "binance", // --> this will be use to determine chain id 56
},
},
我不确定是否需要以下代码:
web3Modal = new Web3Modal({
network: 'binance', // optional
cacheProvider: true,
providerOptions, // required
})
您可以通过直接阅读源代码了解如何配置: //选择BSC Work on Trust Wallet但不Work on Metamask. https://github.com/Web3Modal/web3modal/blob/72596699b97d231dfaa5ef04110b61b8dc77d57d/src/providers/connectors/walletconnect.ts#L30 https://github.com/Web3Modal/web3modal/blob/72596699b97d231dfaa5ef04110b61b8dc77d57d/src/helpers/utils.ts#L198
这篇关于连接到TrustWallet并获取BSC、ETH、BTC地址和余额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文