I creat token contract using remix.

The function approveAndCall code is following.

function approveAndCall(address _spender, uint256 _value, bytes 
_extraData) public
    returns (bool success) {
    allowance[msg.sender][_spender] = _value;
    tokenRecipient spender = tokenRecipient(_spender);
    if (approve(_spender, _value)) {
    spender.receiveApproval(msg.sender, _value, this, _extraData);
    return true;

When I run this function,it shows:

approveAndCall errored: Error encoding arguments: Error: invalid bytes value (arg=undefined, type="number", value=undefined)

What should I string "bytes _extraData"?

enter image description here

2 Answers 2


What I would suggest is to change the datatype of _extraData to string in the meantime while you are still testing your contract in the remix environment to get a readable data and just change it back to bytes when you deploy your contract.

Howver, if you really want to test it using bytes you can just use any of these sample values. 0x1262, 0x12, 0x12


just write 0x00, that will work as seems like your receiveApproval function doesn't use it.

Hope this help.

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.