0

How do I get my own address into a variable when I use HDWallet as provider for Web3?

const HDWalletProvider = require("@truffle/hdwallet-provider");
Web3 = require("web3");
let provider = new HDWalletProvider('claim .. ... ... .. .. blah','https://sandbox.truffleteams.com/blah/blah')

web3 = new Web3(provider);

I have tried:

web3.eth.accounts[0] is empty
web3.currentProvider.selectedAddress is empty
web3.eth.getAccounts(accounts => console.log(accounts[0])) is empty

Nothing seems to work.

  • does the problem persist if you use http instead of https for the URL in the third line? – The Renaissance Sep 24 at 16:51
  • I changed my code to do this, and it works: function getMyAddress(callback){ web3.eth.getAccounts((error,data)=>{ callback(data[0]) }) } – Raven Sep 24 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.