1

I'm attempting to write some test contracts that interacts w/ Uniswap and am using the following stack:

Remix (Injected Web3) -> MetaMask -> Ganache-CLI -> Alchemy (Fork of Ethereum Mainnet)

I start up Ganache with:

ganache-cli -f wss://eth-mainnet.alchemyapi.io/v2/<my-key> -u <address from mainnet: 0x...> -p 7545

If I want to use one of the 9 generated accounts from Ganache, I can easily copy their private key (as displayed in the console), and import it into MetaMask.

However, when I start up Ganache-CLI with the "-u " flag (a valid address that is copied from mainnet to the fork), I don't see that address listed in my 9 Available Accounts / Private Keys... and my goal here is to import that unlocked account into MetaMask.

My questions are:

  1. Does the fact that I don't see the custom -u address in the console list of Unlocked accounts mean I did something wrong?

  2. If I initialized this correctly, is it possible to import this unlocked account into MetaMask (and if so, how? Obviously we're not going to be able to derive a private key from a public address...)

1 Answer 1

1

Hmm.. if you are forking a Mainnet and trying to import accounts that is generated in Mainnet public chain and not yours, then you cannot import it in Metamask!

If it was possible then you could use the funds hold in the address too by switching to Mainnet!

5
  • I'm assuming it's not possible as well... Yet there is a way to use these forked/unlocked accounts in the contracts themselves, so I figured if someone understood how that was working, there might be a path to MetaMask (i.e. the forked account would only work in Ganache... and if I switched to Etherum Mainnet, the account simply would fail).
    – J Shapiro
    Commented May 26, 2022 at 15:21
  • I think you mean that previous transactions are there from forked accounts. That could be history of fork. But I am sure that it is not possible to unlock an account and import it to metamask without private key or mnemonic phrases. That would be massive breach of protocol! Because no matter where you use the account (Ganache or mainnet)if its loaded in metamask means that you can export the private key
    – Mr.SsS
    Commented May 26, 2022 at 15:31
  • Everything you're saying makes perfect sense... but the feature I'm referring to is the "-u" flag for ganache-cli. Here's a demo that uses the "unlocked" account that was forked from mainnet to execute NEW transactions (on Ganche only, of course): github.com/dappuniversity/token_sniping_bot/blob/… The address used there is forked/unlocked when ganache-cli is started (with the -u flag).
    – J Shapiro
    Commented May 26, 2022 at 15:39
  • But the account address is given as unlocked account. Probably something that can be used only on ganache. I am not sure. But still in my thinking, its not possible to import it to Metamask because if it was possible I could put any address and just unlock it? I dont really know.
    – Mr.SsS
    Commented May 26, 2022 at 15:43
  • In any case, it does seem like this is something that can only be triggered from a script vs. MetaMask... it was worth checking! Thank you! (Upvoted your answer)
    – J Shapiro
    Commented May 26, 2022 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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