【Import】

如果我們要從 local 的方式 import 檔案,可以假設 Folder Structure 如下:

├── Import.sol
└── Foo.sol

創建一個名為 Foo.sol 的檔案:

pragma solidity ^0.8.11;

struct Point {
    uint x;
    uint y;
}

error Unauthorized(address caller);

function add(uint x, uint y) pure returns (uint) {
    return x + y;
}

contract Foo {
    string public name = "Foo";
}

接下來創建一個名為 Import.sol 的檔案,並且在裡面 import Foo.sol

當然也可以繼承其他地方來的合約:

如果要從 External 的地方像是 GitHub import 可以藉由複製 url 方式 import:

Last updated

Was this helpful?