0

I need help with adding a new wallet to a web3 instance. e.g.:

web3 = new Web3(new Web3.providers.HttpProvider(connectionString));
const account = await web3.eth.accounts.privateKeyToAccount('0x'+pvKey);
await web3.eth.accounts.wallet.add(account);
console.log(await web3.eth.getAccounts()); // return []..

as you can see, there is no account added to the web3.eth.accounts instance. I need to see the new address added to the accounts list.

web3@1.0.0-beta.36. pow blockchain network. Node v8.11.4

any clue?

0

You are adding an account to the wallet, which is an in-memory object containing multiple accounts (not to the accounts, which is an object containing functions for generating Ethereum accounts).

Change this:

console.log(await web3.eth.getAccounts());

To this:

console.log(web3.eth.accounts.wallet);
  • Thanks for the fast answer, But, when I'm trying to run smart contracts function it is saying to me invalid sender: Returned error: invalid sender [e.g. : await tokenContractInstance.methods.issue(wallet,amount).send({from:webServiceWallet,gas:'4000000'}).catch(ex=> console.log('error1:', ex));] – Nicholas Brodoviz Feb 26 at 14:09
  • @NicholasBrodoviz: What has that got to do with any of the details that you posted in your question, or with any of the details that I wrote in my answer????? – goodvibration Feb 26 at 14:40
  • how I can add a new account to the web3 object to run contract functions? (from specific sender) – Nicholas Brodoviz Feb 26 at 14:46
  • @NicholasBrodoviz: If this is a new question, then please post it in a separate post. – goodvibration Feb 26 at 14:48

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.