Learn Solidity: Importing Ethereum Smart Contracts

In this post, we will learn how to import Ethereum smart contracts in Solidity Language.

Advertisements
World is looking for a Certified Blockchain Expert Become one

Notice: This is one of the multi-post series of Learn Solidity - Build Decentralized Application in Ethereum. This is an attempt to teach you all about Solidity - A Programming Language for Ethereum Based Smart Contracts. If you want to take this as a video course please signup using below button.
pragma solidity ^0.4.9;
contract owned {
    function owned() { owner = msg.sender; }
    address owner;
}
pragma solidity ^0.4.9;

// Solidity supports import statements that are very similar to 
// those available in JavaScript (from ES6 on), although Solidity 
// does not know the concept of a “default export”.

// At a global level, you can use import statements of the following form:


import "./owned.sol";

// import * as symbolName from "filename"; //or 
// import "filename" as symbolName; //both are same
// import {symbol1 as alias, symbol2} from "filename";

// further you can use the contracts of symbols defined in the imported files
contract mortal is owned{
    function kill() {
        selfdestruct(owner);
    }
}
Previous: Inheriting Smart Contracts in Solidity Next: Events & Logging in Solidity