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.
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);
}