我如何在Test()函数中找到A的地址?
contract A {
uint public target;
function setTarget(uint _target) public {
target = _target;
}
}
contract B {
A a = Test(0x123abc...); // address of deployed A
function editA() public {
a.setTarget(1);
}
}
您可以通过将A
类型转换为address
类型来获得地址。
contract B {
A a = Test(0x123abc...);
funciton getAddressA() public view returns (address) {
return address(a); // typecasting to `address`
}
}