blockchainweb3jserc20wallet-connect

Get user's wallet address in web3.js


I need to call an API that requires the user's wallet address. However, I can only get wallet's accounts by web3.eth.getAccounts() but not the wallet address.

I am using WalletConnect and was able to create web3 instance.

Thanks!


Solution

  • You need to use requestAccounts and ask the permission from the user to access their wallet addresses.

    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. Because your question did not contain any example code or repeatable example, it is not possible to tell if you are doing it properly.