Import

The import keyword in solidity is very similar to JavaScript's past version, ES6. It is used to import libraries and other related features into your solidity source file. Solidity does not support export statements.

Here are a few import examples:

import * as symbolName from “solidityFile”

The preceding line shown will create a global symbol called symbolName, containing the global symbol's member from the import file: solidityFile.

Another solidity-specific syntax equivalent to the preceding import is the following:

import solidityFile as symbolName;

You can also import multiple symbols, and name some of the symbols as alias, demonstrated as follows:

import {symbol1 as alias, symbol2} from " solidityFile";

Here is an example where an ERC20 token is created using the zeppelin solidity libraries:

pragma solidity ^0.4.15;
import 'zeppelin/contracts/math/SafeMath.sol';
….
contract ExampleCoin is ERC20 {
  //SafeMath symbol is from imported file SafeMath.sol'
using SafeMath for uint256;

}

For the example shown in the preceding code snippet, we imported the SafeMath library from Zeppelin and applied it to uint256.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset