【合約互動】

我們可以使用 address()contract 型態轉為 address 型態。

如果今天要使用同一個檔案裏面其他合約的函數,可以使用以下方法:

contract A {
  function foo() view external returns(uint) {...}
}

contract B {
  function callFoo(address addrA) external {
    uint result = A(addrA).foo();
  }
}

甚至可以在一個合約裡面宣告其他合約。

contract A {
  constructor(uint a) {...}
  function foo() external {...}
}

contract B {
  function createA(uint a) external {
    A AInstance = new A(a); //pass constructor argument(s) if any
  }
}

Modifier, Inheritance, Importing

Or we can clip the code to two parts(solidity file, Owned.sol and Modifier.sol)

  • Owned.sol

  • Modifier.sol

Last updated

Was this helpful?