1

main contract function which calls my secondary contract

 function gameOver(uint _matchId)public payable onlyOwner returns(bool) {
    Match my_match = Match(matchTracker[_matchId]);
    bool success = my_match.destroy(msg.sender);
    if(success == true)
        delete matchTracker[_matchId];
    return success;

  }

here matchTracker stores the Address of each of the Match contracts

Match contract destroy function

function destroy (address payable _owner)external returns(bool)
        {   require(_owner == owner);
            selfdestruct(owner);
            return true;
        }

Can anyone identify what is wrong? solidity version in use is 0.5.13

1
  • What error are you getting? Is it at compile time or during call execution? How are Match contracts created? Who is the owner of Match contracts?
    – Ismael
    Nov 27, 2019 at 3:15

1 Answer 1

1

selfdestruct requires a parameter of type address payable.

What is the type of owner in your code.? If you're using the OpenZeppelin Ownable.sol, it's not payable.

You could cast it, but since you've already required that _owner is equal to owner, and the former is payable you should simply be able to write

selfdestruct(_owner);

instead.

4
  • my owner is indeed address payable Nov 26, 2019 at 12:17
  • what error are you getting?
    – Zakalwe
    Nov 26, 2019 at 12:43
  • i removed the return from the destroy function and now its working fine..not sure what the issue was though Nov 27, 2019 at 6:25
  • 1
    well, I can't find it explicitly mentioned anywhere, but I think that selfdestruct stops execution of the contract immediately - so your return true will not get called. The return value will either be undefined or 0 (ie false) You don't really need it to return a bool in your example, as it can't fail. The require will abort the transaction as a whole if it's triggered
    – Zakalwe
    Nov 27, 2019 at 10:43

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.