2

I want to check how many tokens are received in my contracts, so that I am able to allocate MY TOKENS to the TOKEN Sender.

I tried several ways like approveAndCall, but its not working.

I don't know, whether is possible or not.

Thank you.

0

Assuming the token sender is sending ERC20 tokens, the best way to do this would be to write a function that transfers the ERC20 tokens to your contract with transferFrom.

The user would have to approve the contract to transfer tokens on their behalf, and the user would also have to submit an amount of tokens to transfer. This function would simply transfer the ERC20 tokens from the sender to the contract, then the it would transfer your token to the sender. It would look something like this:

function swapTokens(uint256 amount) public {
    erc20Token.transferFrom(sender, address(this), amount);
    myToken.transfer(sender, amount);
}

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.