deploying-contracts-on-base
Deploys smart contracts to Base using Foundry. Covers forge create commands, contract verification, testnet faucet setup via CDP, and BaseScan API key configuration. Use when deploying Solidity contracts to Base Mainnet or Sepolia testnet. Covers phrases like "deploy contract to Base", "forge create on Base", "verify contract on BaseScan", "get testnet ETH", "Base Sepolia faucet", "how do I deploy to Base", or "publish my contract".
- License 许可
- AGPL-3.0
- 最近更新
- 2026-11-12
- Stars
- ★ 81
- Forks
- 17
01 前言 Front Matter
- name
- deploying-contracts-on-base
- description
- Deploys smart contracts to Base using Foundry. Covers forge create commands, contract verification, testnet faucet setup via CDP, and BaseScan API key configuration. Use when deploying Solidity contracts to Base Mainnet or Sepolia testnet. Covers phrases like "deploy contract to Base", "forge create on Base", "verify contract on BaseScan", "get testnet ETH", "Base Sepolia faucet", "how do I deploy to Base", or "publish my contract".
02 资源文件 2
- 参考文档SOURCE.md156 B
- 参考文档TRUST.auto.yaml2.3 KB
03 SKILL.md 正文
Deploying Contracts on Base
Prerequisites
- Configure RPC endpoint (testnet:
sepolia.base.org, mainnet:mainnet.base.org) - Store private keys in Foundry's encrypted keystore — never commit keys
- Obtain testnet ETH from CDP faucet (testnet only)
- Get a BaseScan API key for contract verification
Security
- Never commit private keys to version control — use Foundry's encrypted keystore (
cast wallet import) - Never hardcode API keys in source files — use environment variables or
foundry.tomlwith${ENV_VAR}references - Never expose
.envfiles — add.envto.gitignore - Use production RPC providers (not public endpoints) for mainnet deployments to avoid rate limits and data leaks
- Verify contracts on BaseScan to enable public audit of deployed code
Input Validation
Before constructing shell commands, validate all user-provided values:
- contract-path: Must match
^[a-zA-Z0-9_/.-]+\.sol:[a-zA-Z0-9_]+$. Reject paths with spaces, semicolons, pipes, or backticks. - rpc-url: Must be a valid HTTPS URL (
^https://[^\s;|&]+$). Reject non-HTTPS or malformed URLs. - keystore-account: Must be alphanumeric with hyphens/underscores (
^[a-zA-Z0-9_-]+$). - etherscan-api-key: Must be alphanumeric (
^[a-zA-Z0-9]+$).
Do not pass unvalidated user input into shell commands.
Obtaining Testnet ETH via CDP Faucet
Testnet ETH is required to pay gas on Base Sepolia. Use the CDP Faucet to claim it. Supported tokens: ETH, USDC, EURC, cbBTC. ETH claims are capped at 0.0001 ETH per claim, 1000 claims per 24 hours.
Option A: CDP Portal UI (recommended for quick setup)
Agent behavior: If you have browser access, navigate to the portal and claim directly. Otherwise, ask the user to complete these steps and provide the funded wallet address.
- Sign in to CDP Portal (create an account at portal.cdp.coinbase.com/create-account if needed)
- Go to Faucets
- Select Base Sepolia network
- Select ETH token
- Enter the wallet address and click Claim
- Verify on sepolia.basescan.org that the funds arrived
Option B: Programmatic via CDP SDK
Requires a CDP API key and Wallet Secret.
npm install @coinbase/cdp-sdk dotenv
import { CdpClient } from "@coinbase/cdp-sdk";
import dotenv from "dotenv";
dotenv.config();
const cdp = new CdpClient();
const account = await cdp.evm.createAccount();
const faucetResponse = await cdp.evm.requestFaucet({
address: account.address,
network: "base-sepolia",
token: "eth",
});
console.log(`Funded: https://sepolia.basescan.org/tx/${faucetResponse.transactionHash}`);
Environment variables needed in .env:
CDP_API_KEY_ID=your-api-key-id
CDP_API_KEY_SECRET=your-api-key-secret
CDP_WALLET_SECRET=your-wallet-secret
To fund an existing wallet instead of creating a new one, pass its address directly to requestFaucet.
Obtaining a BaseScan API Key
A BaseScan API key is required for the --verify flag to auto-verify contracts on BaseScan. BaseScan uses the same account system as Etherscan.
Agent behavior: If you have browser access, navigate to the BaseScan site and create the key. Otherwise, ask the user to complete these steps and provide the API key.
- Go to basescan.org/myapikey (or etherscan.io/myapikey — same account works)
- Sign in or create a free account
- Click Add to create a new API key
- Copy the key and set it in your environment:
export ETHERSCAN_API_KEY=your-basescan-api-key
Alternatively, pass it directly to forge:
forge create ... --etherscan-api-key <your-key>
Or add it to foundry.toml:
[etherscan]
base-sepolia = { key = "${ETHERSCAN_API_KEY}", url = "https://api-sepolia.basescan.org/api" }
base = { key = "${ETHERSCAN_API_KEY}", url = "https://api.basescan.org/api" }
Deployment Commands
Testnet
forge create src/MyContract.sol:MyContract \
--rpc-url https://sepolia.base.org \
--account <keystore-account> \
--verify \
--etherscan-api-key $ETHERSCAN_API_KEY
Mainnet
forge create src/MyContract.sol:MyContract \
--rpc-url https://mainnet.base.org \
--account <keystore-account> \
--verify \
--etherscan-api-key $ETHERSCAN_API_KEY
Key Notes
- Contract format:
<contract-path>:<contract-name> --verifyflag auto-verifies on BaseScan (requires API key)- Explorers: basescan.org (mainnet), sepolia.basescan.org (testnet)
- CDP Faucet docs: docs.cdp.coinbase.com/faucets
Common Issues
| Error | Cause |
|---|---|
nonce has already been used |
Node sync incomplete |
| Transaction fails | Insufficient ETH for gas — claim from faucet |
| Verification fails | Wrong RPC endpoint for target network |
| Verification 403/unauthorized | Missing or invalid BaseScan API key |
04 同仓库更多 Skills
recipe-performance
Diagnose a specific MetaMask user flow's real-app performance and Sentry critical-user-flow telemetry with deterministic mm-harness recipes. Use for CUF boundaries, cold/warm/background-resume behavior, latency regressions, lifecycle tags, duplicate or blocking network requests, long tasks, layout/paint cost, screen redraws, React rerenders, or browser trace analysis where tests alone cannot prove the real app.
mexc-spot-websocket
MEXC Spot WebSocket workflows for public streams, protobuf handling, depth maintenance, listen keys, and private streams without exposing API keys.
mexc-spot-rest
MEXC Spot REST workflows for public data, signed account requests, orders, wallet/admin actions, and secure signing without exposing API keys.
mexc-futures-websocket
MEXC Futures WebSocket workflows for public streams, private account/order/position streams, ping/pong, subscriptions, and depth maintenance.
0xklen-version-and-refresh-sanctions-lists
暂无简介
verify-tests-cover-changed-lines
Use when a PR adds code that the existing suite may not exercise. Measures patch coverage — the share of newly changed lines hit by tests — before approving.