0

I have erc20 tokens. Now I want to send these tokens to the current contract. How can I send it?

function bid(uint256 tokens) public {
    require(block.timestamp < time,"time exceeded");     
    require(token.balanceOf(msg.sender) >= tokens,"less balance");
    balance[counter][msg.sender] += tokens;
    token.approve(msg.sender, tokens);
    token.transferFrom(msg.sender, address(this), tokens);   
} 

This is what I did but function is not excuting.

1 Answer 1

0

You cannot transfer and approve on the same transaction, you first need to send the approved call, and then the transfer transaction after the approve was mined.

Usually the approve happens in the front end of the dapp if thats what you are using and then you execute the call in your contract that will do the transfer.

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.