Ganache-cli Fork – How to Unlock Account for Transactions

ganache-clitruffle

I'm trying to use ganache-cli on a fork of the Main Network.

I use the following command to start ganache.

ganache-cli –fork https://mainnet.infura.io/v3/MY_API_KEY — unlock 0x6EBaF477F83E055589C1188bCC6DDCCD8C9B131a

Ganache will still give me the 10 account and non of them have this address.

This account is not mine but has a lot of ether in it. So how do I work on the fork with this account?

Truffle will also see me as the first ganache account. And contract deployment will be made under this address and not the one I unlocked.

How do I work from this account without the private key?

It' seam like truffle isn't seeing this unlocked account.

Best Answer

You need to specify the "from" sender account.

If you're trying to make a contract interaction (functional call), then you want something like

MyContract.someFunction(arg1, arg2, { from: "0x6EBaF477F83E055589C1188bCC6DDCCD8C9B131a" })

If you're trying to send ETH from the unlocked account, then you want something like

const someAccount = "0x6635f83421bf059cd8111f180f0727128685bae4"
web3.eth.sendTransaction({from: "0x6EBaF477F83E055589C1188bCC6DDCCD8C9B131a", to: someAccount, value: "1000000000000000000"})
Related Topic