Can somebody please explain what the paramters are in the function approveAndCall that is used in some ERC-20 tokens?

function approveAndCall(address spender, uint tokens, bytes32 data) public returns (bool success) {
    allowed[msg.sender][spender] = tokens;
    emit Approval(msg.sender, spender, tokens);
    ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
    return true;

approveAndCall is a function that combines approving a spender contract to transfer some amount of tokens, and calling a function of that spender.

The amount of tokens that the spender is allowed to spend, is provided in the tokens parameter. The data parameter is used to provide the spender any additional data with which it can decide what specific actions to take.

  • Thanks a lot this help me alot can u tell me more about data parameter what actually i have to pass because when i pass the data fox ex : hello it seems to show error / and when i pass a hex data then it shows gas estimation error
    – NAYAN
    Aug 30 '18 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.