I am in the process of switching to foundry for contract development and testing. I have written some basic contracts, and am trying to use the alchemy RPC URL to deploy the contracts onto the testnet via MetaMask.

I have written tests which pass successfully, but when I try to run forge create ... I get this error:

(code: 3, message: execution reverted, data: Some(String("0x161b906f00000000000000000000000039463d1d009c32806a162df5d7e152d6b4709fda")))

...I haven't managed to find any recurrance of this error on forums etc, so was hoping for some help here.

Here's the create command I am running:

forge create --rpc-url https://eth-goerli.g.alchemy.com/v2/demo --private-key 0x1621e5a0ba99c1a1b10e31240c54241c60ce39f017f9d7fcd94c89012byb36b7 src/MyContractFactory.sol:MyContractFactory

  • Where are you running it from? Are you CD'd into the dir of the project? Commented Aug 1, 2023 at 3:18

1 Answer 1


You should include your Alchemy's API key into your RPC url, like stated in Alchemy's docs: https://eth-goerli.g.alchemy.com/v2/[YOUR-API-KEY]

However they do state that Goerli will be deprecated by January 2024, and they recommend using the Sepolia testnet instead.

Two other things I would consider in your command:

  1. Make sure you're CD'd into the directory you're working in.
  2. Write the name of the contract you're trying to write at the beginning of the statement, like so: forge create MyContractFactory.

Lastly, I really do hope the private key you just posted here is a dummy with no real funds, and in any case - I would store it in an .env file and use an argument instead.
(also relevant to API keys)

A suggested .env file would look like this, using the Sepolia testnet:


Don't forget to source .env in the terminal after saving the file.

Then, your create command would look like this:

forge create MyContractFactory --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY
  • 1
    Concise and clean, thank you. The key is autogen from anvil - but I will edit it anyway, to stop the devils among us.
    – immaxkent
    Commented Aug 1, 2023 at 9:03

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.