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>
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
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
Top comments (0)