To make development easier you can use the import statement in your smart contract to reference contracts stored in other locations. This will allow you to use other contracts / files from Remix or GitHub repositories in your contract while developing and testing. This removes the need to copy and paste contract data.
Using Import in Solidity
How to import a files from a tab into a smart contract in Remix
- Example: contract A and contract B are both in Remix but on different tabs
- Use the following syntax to import one contract into the other in Remix:
Import “./contractName.sol”;
This statement imports all data from contractA into the current global scope of contractB.
Try in Remix
How to import files from GitHub into a smart contract in Remix
- Example: contract B is in Remix but the file we want to import is in GitHub
- Use the following syntax in Remix to import a file from GitHub:
Import “urlfromgithub”;
**Make sure you remove https:// from the url.
This statement imports all data from the GitHub URL into the current global scope of contractB.
Try in Remix
- Make sure the Solidity versions of all your smart contract are the same. To find a different version of a contract in GitHub switch the GitHub branch to the same solidity version your contract is using then copy the URL.
These are the basic methods of using import in Solidity smart contracts.
Click here for more information about how to use the Ethereum test network and how to obtain test ETH.