The import statement

The import keyword helps import other Solidity files and we can access its code within the current Solidity file and code. This helps us write modular Solidity code.

The syntax for using import is as follows:

import <<filename>> ;

File names can be fully explicit or implicit paths. The forward slash / is used for separating directories from other directories and files while . is used to refer to the current directory and .. is used to refer to the parent directory. This is very similar to the Linux bash way of referring to a file. A typical import statement is shown here. Also, note the semicolon towards the end of the statement in the following code:

import 'CommonLibrary.sol';

Get Solidity Programming Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.