0

I'm building a DApp that sends ERC20 Tokens from a browser Metamask account to an escrow contract on the Rinkeby testnet. I'm using a Rinkeby node from Infura, and when I call web3.eth.accounts[0] or web3.eth.getAccounts(), they both return an empty array. I did some digging and figured that since I'm connected to Infura I can't use local accounts. Is there any way to circumvent this? I tried manually providing the account address but that didn't work either.

EDIT: I apologize for not clarifying, I'm trying to run the function web3.personal.unlockAccount(web3.eth.defaultAccount). I get a console error stating the address is invalid because the accounts array is empty.

Abhi Thosar
  • 57
  • 1
  • 5
  • What do you mean by `local accounts`. If you have the private keys you can use the same account on every network (the account, of course, has a different balance on each network). – nikos fotiadis Feb 23 '19 at 20:34
  • @nikosfotiadis, how would I go about doing this? What's the syntax I mean? What I'm trying to do is web3.personal.unlockAccount(address), but the address, of course, is invalid, so do I instantiate and insert an account object instead? – Abhi Thosar Feb 23 '19 at 20:37
  • If you have the mnemonic of the account you can use https://github.com/trufflesuite/truffle-hdwallet-provider to unlock the account. If you have the private key you can follow the instructions here to get the account from the private key https://github.com/ethereum/web3.js/issues/1527 – nikos fotiadis Feb 23 '19 at 20:40
  • @nikosfotiadis thank you so much! Will try and report back – Abhi Thosar Feb 23 '19 at 21:44
  • @nikosfotiadis it worked! Thanks :) – Abhi Thosar Feb 25 '19 at 05:51

0 Answers0