Closed rawadrifai closed 5 years ago
More info on this:
truffle migrate
works fine if I configure my truffle.js correctly.
However, unit tests that declare a new HDWalletProvider fail as shown above.
I am quite new to this myself, but, It looks like you are trying to use a coinbase eth wallet as the from
account. I would love to be able to do this myself, but, I think you need to either auth the account, or, unlock it if you have the account password.
If I am correct your new HDWalletProvider
auths a wallet itself when you pass it a "mnemonic". like so:
const mnemonic = process.env.WALLET_MNEMONIC;
const provider = new HDWalletProvider(mnemonic, process.env.WEB3_PROVIDER, 0);
const web3 = new Web3(provider);
const accounts = await web3.eth.getAccounts();
const web3account = accounts[0];
So web3account
is an account you can use in your from property at this point.
Funnily enough, I want to do exactly this myself, and, I even posted a question earlier today which has now been answered.
Feel free to upvote me on stackexchange 💃
@joepagan - which version of web3 are you using? I'm using 0.20.x and the await web3.eth.getAccounts()
is returning undefined for me. I wonder if it's the web3 version.
So the only thing I am doing differently is hardcoding the account address as opposed to calling getAccounts. Are you saying the getAccounts auto unlocks the accounts?
Furthermore, are you able to do something similar with a private key instead of mnemonic?
Thank you and I will upvote you on stackexchange.
btw - I'm not sure if by "Coinbase" you meant the company in San Francisco. They took their name from eth's coinbase (which is the default account). That's what I refer to in my code.
more info -
If I follow @joepagan instructions it will throw this error on web3.eth.getAccounts()
:
Error: Web3ProviderEngine does not support synchronous requests.
ok I figured it out.. just needed to do coinbase.toLowerCase(). It now finds the account.
It fails when I call a function of an initiated truffle contract.
Error: the string "Account not found" was thrown, throw an Error :) at process._tickCallback (internal/process/next_tick.js:68:7)