1

Getting two errors with the following code.

abstract contract ReceiveBalanceContract is Ownable {

    receive() external payable {
        require(msg.sender == address(SendBalanceContract));
    }

    function withdrawBalance() external {

        owner.call.value(address(this).balance)();
    }
}

contract SendBalanceContract {

    constructor(address _nftAddress) public {

        ERC721 candidateContract = ERC721(_nftAddress);
        require(candidateContract.supportsInterface(InterfaceSignature_ERC721)); 
        nonFungibleContract = candidateContract;
    }

    function withdrawBalance() external {
        address nftAddress = address(nonFungibleContract);

        require(msg.sender == owner || msg.sender == nftAddress); // Error 1
        bool res = nftAddress.call.value(address(this).balance)(""); // Error 2
    }
}

I am getting two errors and can't manage to fix this. Error 1:

TypeError: Operator == not compatible with types address payable and function () view returns (address)
require(msg.sender == owner || msg.sender == nftAddress);

Error 2:

TypeError: Different number of components on the left hand side (1) than on the right hand side (2).

I don't understand what s going on here

2
  • What imports are you using? Are you using OpenZeppelin? What version? The code as supplied has several additional errors: "Identifier not found or not unique: Ownable, ERC721", "Undeclared identifier: nonFungibleContract, owner", etc.
    – Ismael
    Commented May 15, 2020 at 16:23
  • 1
    Sorry my bad, I posted the correct code and solution to my mistake as an answer. Commented May 16, 2020 at 13:04

1 Answer 1

1

Down below is the correct code and my mistakes were due to: call.value returns two value (bool, bytes memory) (not just bool) and the new Ownable contract has no public access variable owner anymore, but instead a function owner() to get the address of contract owner.

pragma solidity ^0.6.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/introspection/ERC165Checker.sol";

abstract contract ReceiveBalanceContract is Ownable, ERC721 {

    SendBalanceContract public saleAuction;

    receive() external payable {
        address auctionContract = address(saleAuction);
        require(msg.sender == auctionContract);
    }

    function withdrawBalance() external {

        owner().call{value: address(this).balance}("");
    }
}

contract SendBalanceContract is Ownable {

    using ERC165Checker for address; // pm added librairy. Not sure this is address

    ERC721 public nonFungibleContract;

    bytes4 constant InterfaceSignature_ERC721 = bytes4(0x9a20483d);

    constructor(address _nftAddress) public {

        ERC721 candidateContract = ERC721(_nftAddress);
        require(candidateContract.supportsInterface(InterfaceSignature_ERC721)); 
        nonFungibleContract = candidateContract;
    }

    function withdrawBalance() external {
        address nftAddress = address(nonFungibleContract);

        require(msg.sender == owner() || msg.sender == nftAddress);
        // We are using this boolean method to make sure that even if one fails it will still work
        (bool sent, bytes memory data) = nftAddress.call{value:address(this).balance}("");
    }
}

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.