0

Transfer function not changing custom token(ERC20) balance after successful transfer from transfer function ?

The transaction is successfully performed but the amount of custom token in my wallet does not change after the transaction is completed. Why is that ?

function insertPartcipantsInJackpot(address tokenAddress,uint256 counter,address payable participant) override external 
    {   
        console.log("Over here 1");
        require(IERC20(tokenAddress).balanceOf(address(this)) >= _jackPots[counter]._entryFee,
         "Not Sufficent Funds");

        console.log("Over here 2");
        require(_jackPots[counter]._endTime > _dateTime._now(),
        "This Participant Cannot Enter This Jackpot, Because The Event has already started");
        

        console.log("Over here 3");
        //token.transfer(0x001286211EcDb2ED5043f50d6634d7be924eF5D9,_jackPots[counter]._entryFee);         
        AkumaCoin(0xcDCE1e8407b065dC121bed39Cc316feB1E404965).transfer(address(this),_jackPots[counter]._entryFee);
        //deduct that amount,sent to owner account or can be done to contract itself

        _jackPots[counter]._prizePool += _jackPots[counter]._entryFee;
        //put that entry fee in that pool

        _jackPots[counter]._toMint++;

        _jackPots[counter]._participants.push(participant);
    }

1 Answer 1

0

Ok, Whilst in progress with a project I was doing, The transfer function cannot be used for this. So instead use transferFrom function that is provided by ERC20. But to use it, You first need to give ownership to spend your custom tokens then you can successfully use the transferFrom function. It is essential to give ownership to the spender either a (smart contract or a wallet), If you dont then it'll display a message of this sort insufficient allowance warning before the transaction and It'll eventually fail.

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.