'What are the rules (syntax) for importing from Github repo to Solidity Contract
I have the following import statement in a Solidity contract ( this works).
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"
The interface I'm importing is at the following repo: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol
My question is, what is the syntax or rules I should follow when importing from a github repo to Solidity? what does the @ sign in the import statement mean ?
Solution 1:[1]
Your snippet shows a direct import that searches for the file in your local directories based on the compiler config.
One of the default sources is the node_modules directory where NPM packages are installed.
The @ symbol is just a prefix of NPM scoped packages, allowing to group more packages into the same namespace (in this case @openzeppelin/<package_name>).
To import a contract from GitHub, you can just pass its full URL:
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol";
Again because of the default config, the compiler downloads the remote file from GitHub to a local temp directory, and imports its contents before compiling.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Petr Hejda |
