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:
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
Best Answer
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:
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: