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 ?
CodePudding user response:
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.