A CLI tool to download verified smart contract source code from Etherscan and other Etherscan-powered block explorers using the official V2 API.
- Multi-Chain Support: Download contracts from Ethereum, Base, Arbitrum, Polygon, and any other chain supported by the Etherscan V2 API.
- Correct File Structure: Automatically parses the Standard JSON Input format to recreate the correct directory structure and file paths.
- Easy to Use: Simple and intuitive command-line interface.
- Environment Variable Support: Configure your API key once in a .env file.
You can run savecontract directly using npx without installation.
Or, you can install it globally for easier access:
| --address | -a | (Required) The contract address to download. | - |
| --chainid | -c, -cid | Chain ID or name (e.g., "1", "ethereum", "8453", "base"). | "1" (Ethereum) |
| --output | -o | The output directory for the contract files. | ./smartcontracts |
| --apikey | -k | Your Etherscan API key. Overrides the environment variable. | - |
| --module | -m | API module to use. | "contract" |
| --action | API action to use. | "getsourcecode" | |
| --help | -h | Show help. | - |
| --version | -v | Show version number. | - |
An Etherscan API key (from the free tier) is required. You can provide it in two ways:
-
Via Command Line (highest priority):
savecontract -a 0x... -k YOUR_API_KEY -
Via .env file (recommended): Create a .env file in the directory where you are running the command and add your key:
ETHERSCAN_API_KEY=YOUR_API_KEY
1. Download a contract from Base mainnet:
(This assumes your API key is in a .env file)
2. Download a contract from Ethereum mainnet (default chain):
3. Specify API key directly for a contract on Polygon:
This tool supports any chain available on the Etherscan V2 API. Use either the chain ID or one of the convenient names below:
- ethereum, mainnet (ID: 1)
- sepolia (ID: 11155111)
- base (ID: 8453)
- arbitrum (ID: 42161)
- polygon (ID: 137)
- optimism, op (ID: 10)
- bsc, bnb (ID: 56)
- avalanche, avax (ID: 43114)
- ...and many more.
MIT
.png)



