|
5 | 5 | </a> |
6 | 6 | </p> |
7 | 7 | <br/> |
8 | | - |
9 | | - ## Tip |
| 8 | + |
| 9 | +> [!IMPORTANT] |
| 10 | +> This branch contains the Hardhat 2 starter kit. For Hardhat 3, see the [hardhat-3 branch](https://github.com/smartcontractkit/hardhat-starter-kit/tree/hardhat-3). This branch uses Solidity [Remapping](#import-remapping) and the [hardhat-preprocessor](https://www.npmjs.com/package/hardhat-preprocessor) plugin to resolve imports correctly. <b>If you have errors when compiling dependencies please consult the [Remapping](#import-remapping) section of this README. </b> |
| 11 | +
|
| 12 | +## Tip |
10 | 13 | > Please be attention that Chainlink Any API is removed from this starter kit because Chainlink Any API is currently replaced by [Chainlink Functions](https://docs.chain.link/chainlink-functions). Please find the starter kit for Chainlink Functions [here](https://github.com/smartcontractkit/functions-hardhat-starter-kit) |
11 | 14 |
|
12 | 15 | [](https://gitpod.io/#https://github.com/smartcontractkit/hardhat-starter-kit) |
|
35 | 38 | - [Estimating Gas](#estimating-gas) |
36 | 39 | - [Code Coverage](#code-coverage) |
37 | 40 | - [Fuzzing](#fuzzing) |
| 41 | +- [Import Remapping](#import-remapping) |
38 | 42 | - [Contributing](#contributing) |
39 | 43 | - [Thank You!](#thank-you) |
40 | 44 | - [Resources](#resources) |
@@ -176,7 +180,7 @@ You can get one for free from [Alchemy](https://www.alchemy.com/), [Infura](http |
176 | 180 |
|
177 | 181 | This is your private key from your wallet, ie [MetaMask](https://metamask.io/). This is needed for deploying contracts to public networks. You can optionally set your `MNEMONIC` environment variable instead with some changes to the `hardhat.config.js`. |
178 | 182 |
|
179 | | - **WARNING**  |
| 183 | +**⚠️ WARNING ⚠️** |
180 | 184 |
|
181 | 185 | When developing, it's best practice to use a Metamask that isn't associated with any real money. A good way to do this is to make a new browser profile (on Chrome, Brave, Firefox, etc) and install Metamask on that browser, and never send this wallet money. |
182 | 186 |
|
@@ -436,6 +440,24 @@ To exit Echidna type |
436 | 440 | exit |
437 | 441 | ``` |
438 | 442 |
|
| 443 | +# Import Remapping |
| 444 | + |
| 445 | +In Solidity, [remapping](https://docs.soliditylang.org/en/latest/path-resolution.html#import-remapping) is a way to define shorthand import paths so that developers can avoid writing long relative paths when importing contracts. For example, instead of writing `import "../../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol";`, you could define a remapping such as `@openzeppelin/=node_modules/@openzeppelin/` and simply use `import "@openzeppelin/contracts/token/ERC20/ERC20.sol";`. This makes contract imports cleaner, easier to maintain, and more consistent across different projects. Remappings are commonly used in development environments like [Foundry](https://getfoundry.sh/guides/project-setup/dependencies/#remapping-dependencies) or [Hardhat 3](https://hardhat.org/docs/), but Hardhat 2 does not support them natively. |
| 446 | + |
| 447 | +To work around this limitation, you can use the [hardhat-preprocessor](https://www.npmjs.com/package/hardhat-preprocessor) plugin, which preprocesses Solidity files before compilation and rewrites the imports according to your remapping rules. This plugin works by extending the available configuration options of the expected [`HardhatUserConfig`](https://v2.hardhat.org/hardhat-runner/docs/config) object to include a preprocess property. |
| 448 | + |
| 449 | +This starter kit contains example code of this workaround in action within the [`remappings-helper.js`](./remappings-helper.js) file, and uses the remappings located within [`remappings.txt`](./remappings.txt). |
| 450 | + |
| 451 | +> [!WARNING] |
| 452 | +> The [hardhat-preprocessor](https://www.npmjs.com/package/hardhat-preprocessor) plugin is a third-party plugin. |
| 453 | +> Use it at your own discretion and review its source before adopting it in any production environments. |
| 454 | +
|
| 455 | +## Adding your own remappings |
| 456 | + |
| 457 | +As your project expands, you may find the need for more dependencies. This may result in the requirement of additional remappings. To include more remappings, simply add your remapping to the `remappings.txt` file. |
| 458 | + |
| 459 | +The expected syntax is: `<prefix>=<resolved-path>` |
| 460 | + |
439 | 461 | # Contributing |
440 | 462 |
|
441 | 463 | Contributions are always welcome! Open a PR or an issue! |
|
0 commit comments