简体   繁体   English

在 web3.js 中获取用户的钱包地址

[英]Get user's wallet address in web3.js

I need to call an API that requires the user's wallet address.我需要调用一个需要用户钱包地址的 API。 However, I can only get wallet's accounts by web3.eth.getAccounts() but not the wallet address.但是,我只能通过web3.eth.getAccounts()获取钱包的帐户,而不是钱包地址。

I am using WalletConnect and was able to create web3 instance.我正在使用 WalletConnect 并且能够创建 web3 实例。

Thanks!谢谢!

You need to use requestAccounts and ask the permission from the user to access their wallet addresses.您需要使用requestAccounts并请求用户的许可才能访问他们的钱包地址。

Due to privacy reasons, the website cannot do this by default.由于隐私原因,本网站默认无法执行此操作。

Also, you need to set up your Web3 properly with the wallet in the order it to work.此外,您需要使用钱包正确设置 Web3 才能正常工作。 Because your question did not contain any example code or repeatable example, it is not possible to tell if you are doing it properly.因为您的问题不包含任何示例代码或可重复的示例,所以无法判断您是否正确执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM