Deploying
This guide covers deploying your magical-nft contracts to various networks.
Deployment Options
magical-nft provides several deployment scripts:
| Script | Description |
|---|---|
DeployFull{{ProjectName}}.s.sol | Deploy all contracts at once |
DeployOnly{{ProjectName}}.s.sol | Deploy only the main contract |
DeployOnly{{ProjectName}}Renderer.s.sol | Deploy only the renderer |
DeployOnly{{ProjectName}}Storage.s.sol | Deploy only storage |
Local Development
Start Anvil
anvilDeploy All Contracts
forge script script/DeployFull{{ProjectName}}.s.sol \
--rpc-url http://localhost:8545 \
--broadcastTestnet Deployment
Configure Environment
Make sure your .env file has the required values:
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY
PRIVATE_KEY=0x...
ETHERSCAN_API_KEY=...Deploy to Sepolia
source .env
forge script script/DeployFull{{ProjectName}}.s.sol \
--rpc-url $SEPOLIA_RPC_URL \
--broadcast \
--verifyMainnet Deployment
Pre-flight Checklist
- All tests passing
- Contracts verified on testnet
- Metadata rendering correctly
- Gas costs estimated
- Owner addresses confirmed
Deploy to Mainnet
forge script script/DeployFull{{ProjectName}}.s.sol \
--rpc-url $MAINNET_RPC_URL \
--broadcast \
--verify \
--slowThe --slow flag helps avoid rate limiting during verification.
Post-Deployment
Verify Contracts
If automatic verification failed:
bun run verifyUpload Assets
After deployment, upload your assets:
bun run upload-all-filesRecord Addresses
Save your deployed contract addresses in a safe place:
- Main Contract:
0x... - Renderer:
0x... - Storage:
0x...
Upgrading Contracts
To upgrade the renderer without affecting existing tokens:
- Deploy new renderer:
DeployOnly{{ProjectName}}Renderer.s.sol - Call
setRenderer(newAddress)on main contract - Verify new metadata is rendering correctly