-
Notifications
You must be signed in to change notification settings - Fork 0
Deployment
Brandon Brooks edited this page Jan 22, 2026
·
1 revision
This guide covers deploying ContractKit projects to local and test networks.
/contractkit:localOr manually:
anvilAnvil provides:
- 10 pre-funded accounts (10,000 ETH each)
- Instant block mining
- RPC at
http://127.0.0.1:8545
/contractkit:deploy localOr manually:
forge script script/Deploy.s.sol --rpc-url http://127.0.0.1:8545 --broadcast --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80/contractkit:call <address> name()-
Sepolia ETH - Get from a faucet:
-
RPC URL - From a provider:
-
Private Key - Export from your wallet (never share this!)
Create a .env file (add to .gitignore!):
PRIVATE_KEY=0x...your_private_key...
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/your-api-keyLoad environment:
source .env/contractkit:deploy sepoliaOr manually:
forge script script/Deploy.s.sol \
--rpc-url $SEPOLIA_RPC_URL \
--broadcast \
--private-key $PRIVATE_KEY \
--verifyIf not auto-verified, manually verify:
forge verify-contract <address> src/Token.sol:Token \
--chain sepolia \
--etherscan-api-key $ETHERSCAN_API_KEYEach template includes deployment scripts in script/:
Basic deployment script:
contract DeployScript is Script {
function run() public {
vm.startBroadcast();
Token token = new Token("MyToken", "MTK");
console.log("Token deployed at:", address(token));
vm.stopBroadcast();
}
}Post-deployment interactions:
contract InteractScript is Script {
function run() public {
address tokenAddress = vm.envAddress("TOKEN_ADDRESS");
Token token = Token(tokenAddress);
vm.startBroadcast();
// Grant minter role
token.grantRole(token.MINTER_ROLE(), msg.sender);
// Mint tokens
token.mint(msg.sender, 1000 ether);
vm.stopBroadcast();
}
}Run with:
TOKEN_ADDRESS=0x... forge script script/Interact.s.sol --rpc-url $RPC_URL --broadcast --private-key $PRIVATE_KEYBefore deploying to mainnet:
- Independent security audit completed
- All tests passing
- No compiler warnings
- Reviewed THREAT_MODEL.md
- Checked SECURITY.md considerations
- Constructor parameters verified
- Access control roles planned
- Initial token distribution planned (if applicable)
- Upgrade path considered (if applicable)
- Deployment wallet secured (hardware wallet recommended)
- Sufficient ETH for gas
- Etherscan verification planned
- Monitoring/alerting set up
- Incident response plan ready
- Contract verified on block explorer
- Initial roles granted
- Functionality tested on mainnet
- Documentation updated with addresses
Foundry saves deployment records in broadcast/:
broadcast/
└── Deploy.s.sol/
├── 31337/ # Local (Anvil)
│ └── run-latest.json
└── 11155111/ # Sepolia
└── run-latest.json
Each log contains:
- Transaction hashes
- Contract addresses
- Gas used
- Timestamps
| Network | Chain ID | RPC |
|---|---|---|
| Anvil (local) | 31337 | http://127.0.0.1:8545 |
| Sepolia | 11155111 | Provider URL |
| Mainnet | 1 | Provider URL |
- Check wallet balance
- Get testnet ETH from faucet
- Reset account in MetaMask, or
- Wait for pending transactions
- Ensure exact same compiler version
- Check constructor arguments match
- Try flattening:
forge flatten src/Contract.sol
- Check RPC URL is correct
- Verify private key format (0x prefix)
- Ensure network is reachable
ContractKit
Reference
Help