$npx -y skills add OpenZeppelin/openzeppelin-skills --skill setup-solidity-contractsSet up a Solidity smart contract project with OpenZeppelin Contracts. Use when users need to: (1) create a new Hardhat or Foundry project, (2) install OpenZeppelin Contracts dependencies for Solidity, (3) configure remappings for Foundry, or (4) understand Solidity import convent
| 1 | # Solidity Setup |
| 2 | |
| 3 | For existing projects, detect the framework by looking for `hardhat.config.*` (Hardhat) or `foundry.toml` (Foundry). For new projects, ask the user which framework they prefer. |
| 4 | |
| 5 | ## Hardhat Setup |
| 6 | |
| 7 | - Initialize project (only if starting a new project) |
| 8 | |
| 9 | ```bash |
| 10 | npx hardhat init # Hardhat v2 |
| 11 | npx hardhat --init # Hardhat v3 |
| 12 | ``` |
| 13 | |
| 14 | - Install OpenZeppelin Contracts: |
| 15 | |
| 16 | ```bash |
| 17 | npm install @openzeppelin/contracts |
| 18 | ``` |
| 19 | |
| 20 | - If using upgradeable contracts, also install the upgradeable variant: |
| 21 | |
| 22 | ```bash |
| 23 | npm install @openzeppelin/contracts-upgradeable |
| 24 | ``` |
| 25 | |
| 26 | ## Foundry Setup |
| 27 | |
| 28 | - Install Foundry |
| 29 | |
| 30 | ```bash |
| 31 | curl -L https://foundry.paradigm.xyz | bash |
| 32 | foundryup |
| 33 | ``` |
| 34 | |
| 35 | - Initialize project (only if starting a new project) |
| 36 | |
| 37 | ```bash |
| 38 | forge init my-project |
| 39 | cd my-project |
| 40 | ``` |
| 41 | |
| 42 | - Add OpenZeppelin Contracts: |
| 43 | |
| 44 | ```bash |
| 45 | forge install OpenZeppelin/openzeppelin-contracts@v<VERSION> |
| 46 | ``` |
| 47 | |
| 48 | - If using upgradeable contracts, also add the upgradeable variant: |
| 49 | |
| 50 | ```bash |
| 51 | forge install OpenZeppelin/openzeppelin-contracts-upgradeable@v<VERSION> |
| 52 | ``` |
| 53 | |
| 54 | > Look up the current version from https://github.com/OpenZeppelin/openzeppelin-contracts/releases. Pin to a release tag — without one, `forge install` pulls the default branch, which may be unstable. |
| 55 | |
| 56 | - `remappings.txt` (if not using upgradeable contracts) |
| 57 | |
| 58 | ```text |
| 59 | @openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/ |
| 60 | ``` |
| 61 | |
| 62 | - `remappings.txt` (if using upgradeable contracts) |
| 63 | |
| 64 | ```text |
| 65 | @openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/ |
| 66 | @openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/ |
| 67 | ``` |
| 68 | |
| 69 | > **Note** |
| 70 | > The above remappings mean that both `@openzeppelin/contracts/` (including proxy contracts) and `@openzeppelin/contracts-upgradeable/` come from the `openzeppelin-contracts-upgradeable` submodule and its subdirectories, which includes its own transitive copy of `openzeppelin-contracts` of the same release version number. This format is needed for Etherscan verification to work. Particularly, any copies of `openzeppelin-contracts` that are installed separately are NOT used. |
| 71 | |
| 72 | ## Import Conventions |
| 73 | |
| 74 | - Standard: `@openzeppelin/contracts/token/ERC20/ERC20.sol` |
| 75 | - Upgradeable: `@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol` |
| 76 | - Use upgradeable variants only when deploying behind proxies; otherwise use standard contracts. |