DEV Community

Cover image for Ethereum-Solidity Quiz Q8: How can you deploy a Solidity smart contract with Foundry?
MihaiHng
MihaiHng

Posted on

Ethereum-Solidity Quiz Q8: How can you deploy a Solidity smart contract with Foundry?

A Solidity smart contract can be deployed with Foundry in two main ways: using forge create for simple deployments or using forge script for more complex scenarios.

Method 1: Using forge create

forge create src/MyContract.sol:MyContract \
  --rpc-url <RPC_URL> \
  --private-key <PRIVATE_KEY> 
Enter fullscreen mode Exit fullscreen mode

Method 2: Using forge script when there is a deployment script.

forge script script/Deploy.s.sol \
  --rpc-url <RPC_URL> \
  --private-key <PRIVATE_KEY> \
  --broadcast
Enter fullscreen mode Exit fullscreen mode

For more info and flags use forge create --help or forge create --help

Important Note: You should never use your PRIVATE_KEY in plain text as suggested above(only an example) -> NOT SAFE
Instead use a --keystore Account, that stores your private key and lets you use it without revealing it.

forge script script/Deploy.s.sol \
  --rpc-url <RPC_URL> \
  --keystore <ACCOUNT> \
  --broadcast
Enter fullscreen mode Exit fullscreen mode

Top comments (0)