1

I am trying to read an address parameter in contract B from contract A and assert equality, but i get a type error:

TypeError: Operator == not compatible with types function () view external returns (address) and address

code:

contract A{
    ...
    function confirm(B _address) public returns(bool){
        B b = b(_address);
        require(b._addr == msg.sender);
        return true;
    }
    ...
}
contract B{
    address public _addr;
    ... 
}

Thank you very much :)

2 Answers 2

5

Variables behave like functions from the perspective of other contracts.

The error is telling you that b._addr is not an address, but a function that returns an address.

In contract A, try doing b._addr() instead of b._addr

0
1

Adding to @Jesse Busman 's answer, the methods of an address will also be available after calling the variable as a function:

contract B {
    address public owner;
}

contract A {
    B public b;

    constructor(B _contract) public {
        b = _contract;
    }

    function myTransferMethod() public {
        b.owner().transfer(msg.value);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.