我正在尝试获取已部署合约A
的地址,但创建一个新的 AA first = new A();
生成具有新地址的新合约。
pragma solidity ^0.5.0;
contract A {
address public contract_A_address =address(this);
address public owner_A = msg.sender;
}
contract B {
address public contract_B_address =address(this);
address public owner_B = msg.sender;
A first = new A();
function Get_first_Address() public view returns(address){
return address(first);
}
function Get_Contract_A_Address() public view returns(address){
return ??? ;
}
}
合同 BGet_Contract_A_Address()
所需的输出应与合同 A 的contract_A_address
相同
我没有看到使用:
第一个 = 新的 A((;
因为 A 是另一个合约,部署在 B 之前,所以可以使用继承:
contract B is A { ...
#then the variable contract_A_address is available
OR contract_A_address可以作为参数放在 B 的构造函数中,以便在部署过程中填充:
contract B {
contructor(address contract_A_address) public { ...