You are viewing a single comment's thread from:

RE: Solidity开发指南

in #starnotelast month

import * as symbolName from "filename";
import "filename" as symbolName;
然后所有函数都以symbolName.symbol格式提供。

import 相当于接口,导入其它合约的函数,不过函数的执行环境不变,仍在原有合约中执行。例如:B中导入A,A.send()仍会在A的环境中执行。
import 演化成库和接口(interface), 标准化程度更高。

contract A {
    function add (uint x, uint y) public pure returns (uint) {
        return x.plus(y);
    }
}

import "./A.sol"
contract B {
    function add2 (A a, uint x, uint y) public pure returns (uint) {
        return a.add(x,y)
    }
}