A solidity source file can contain:
- contract definitions
- import directives
- pragma directives
Pragmas:
- used to enable certain compiler features or checks
- each file should have a pragma
- while importing a file into another file, pragma does not automatically apply
Versioning:
The version of pragma is used as follows:
pragma solidity ^0.5.2;
A source file with the line above does not compile with a compiler earlier than version 0.5.2,
and it also does not work on a compiler starting from version 0.6.0 (this
second condition is added by using ^). This is because
there will be no breaking changes until version 0.6.0, so you can always
be sure that your code compiles the way you intended.
Importing Other Source Files
In solidity, import is used to create modular structure of the project similar to JavaScript(ES6) but doesn't support the concept of default export.
import "filename";
The above mentioned format is not supported as it pollutes the namespace. A better way to import is:
import * as symbolName from "filename";
Or
import "filename" as symbolName;
Note: filename here is the path to the file which can be written using: ./ or ./../
Comments
Single-line comments (
//) and multi-line comments (/*...*/) are possible.
// single line
/*
Multi-line
comment
*/
Comments
Post a Comment