| name | deploying-contracts-on-abstract |
| description | Deploy smart contracts on Abstract using Foundry (default) or Hardhat. Covers zksolc compilation, deployment, Abscan verification, and testnet faucets for the Abstract Ethereum L2. This skill should be used when deploying or compiling contracts on Abstract, using forge/foundry-zksync, forge build --zksync, forge create --zksync, anvil-zksync, verifying on Abscan, or working with the zkSync compiler on Abstract. |
Deploying Contracts on Abstract
Default: Foundry. Abstract uses the ZK Stack VM — contracts must be compiled with zksolc, not standard solc. For Hardhat, see references/hardhat.md. For EVM differences, see references/evm-differences.md.
Foundry Setup
1. Install foundry-zksync
curl -L https://raw.githubusercontent.com/matter-labs/foundry-zksync/main/install-foundry-zksync | bash
foundryup-zksync
Warning: This overwrites standard Foundry. Switch back with foundryup if needed.
2. Create project
forge init my-abstract-project && cd my-abstract-project
3. Configure foundry.toml
[profile.default]
src = 'src'
libs = ['lib']
fallback_oz = true
is_system = false
mode = "3"
[etherscan]
abstractTestnet = { chain = "11124", url = "https://api-sepolia.abscan.org/api", key = "${ABSCAN_API_KEY}" }
abstractMainnet = { chain = "2741", url = "https://api.abscan.org/api", key = "${ABSCAN_API_KEY}" }
4. Compile
forge build --zksync
Outputs to zkout/ (not out/).
Deploy
Store private key securely
cast wallet import myKeystore --interactive
Fund the deployer
Deploy + verify (testnet)
forge create src/Counter.sol:Counter \
--account myKeystore \
--rpc-url https://api.testnet.abs.xyz \
--chain 11124 \
--zksync \
--verify \
--verifier etherscan \
--verifier-url https://api-sepolia.abscan.org/api \
--etherscan-api-key ${ABSCAN_API_KEY}
Deploy + verify (mainnet)
forge create src/Counter.sol:Counter \
--account myKeystore \
--rpc-url https://api.mainnet.abs.xyz \
--chain 2741 \
--zksync \
--verify \
--verifier etherscan \
--verifier-url https://api.abscan.org/api \
--etherscan-api-key ${ABSCAN_API_KEY}
Constructor arguments
Append --constructor-args <arg1> <arg2> in the order defined in the constructor.
Verify an Existing Contract
forge verify-contract <address> src/Counter.sol:Counter \
--chain 11124 \
--etherscan-api-key ${ABSCAN_API_KEY} \
--zksync
Use --chain 2741 for mainnet. Chain names (abstract-testnet, abstract) also work.
Testing
forge test --zksync
Fork testing against live networks:
forge test --zksync --fork-url https://api.testnet.abs.xyz
Local node:
anvil-zksync
forge test --zksync --fork-url http://localhost:8011
Cheatcode limitation: On Abstract's ZK VM, cheatcodes (vm.prank, vm.roll, etc.) only work at the root test level — not from within contracts being tested.
Decision: Foundry vs Hardhat
| Scenario | Use |
|---|
| Solidity-first, fast iteration | Foundry (default) |
| TypeScript preference | Hardhat (references/hardhat.md) |
| Existing Hardhat project | Hardhat (references/hardhat.md) |
| Existing Foundry project | Foundry |
| Need JS plugin ecosystem | Hardhat (references/hardhat.md) |
Gotchas
- All
forge commands need --zksync — without it, you get standard EVM bytecode that won't run on Abstract
foundryup-zksync overwrites standard Foundry — use foundryup to switch back
- Abscan API key required — get one from abscan.org; set via
export ABSCAN_API_KEY=<key> or .env
zkout/ not out/ — compiled artifacts go to a different directory
- Never commit private keys — use
cast wallet import or environment variables