Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 730
maskara Avatar asked Oct 14 '25 16:10

maskara


1 Answers

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.

like image 150
Petr Hejda Avatar answered Oct 17 '25 09:10

Petr Hejda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!