1

Here is the code snipped which is used when I'am working with compiler version 0.4.6 :

function approveAndCall(address _spender, uint256 _value, bytes memory _extraData) public returns (bool success) {
        allowed[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);
        if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { 
            throw; 
        }
        return true;
    }

Now I'm compiling this code with version 0.5.1, what should I do? I've already referred Read the Docs content : v0.5.0 Breaking Changes, but really I didn't understand it.

1 Answer 1

2

I am not sure about below code may resolve your problem or not. You may try the following and let me know about the result.

 function approveAndCall(address _spender, uint256 _value, bytes memory _extraData) public returns (bool success) {
    allowed[msg.sender][_spender] = _value;
    emit Approval(msg.sender, _spender, _value);
    (bool success, bytes memory data)  = address(_spender).call(abi.encode(
        bytes4(
            bytes32(
                keccak256(
                    abi.encodePacked(
                        "receiveApproval(address,uint256,address,bytes)"
                    )
                )
            )
        ),
        msg.sender, _value, this, _extraData))
    ;
    require(success);
    return true;
}
1
  • @ Mehmet Doğan Thanks a lot. Result is, your solution worked successfully...
    – Rudrika
    Commented Feb 28, 2019 at 11:04

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.