Batch transfer function not transferring token

Hello, I have been struggling for days now trying to figure this out so any tips would be highly appreciable.

I am attempting to batch transfer tokens to an array of addresses with a function like this:

    function batchTransferToken(address[] memory holders, uint256 amount) public payable {
        for (uint i=0; i<holders.length; i++) {
            emit Transfer(address(this), holders[i], amount);

The transaction is successful but the token simply does not move to target wallet addresses. I have made sure contract has required tokens for transfer.

Here is example transaction:

I have seen other people use this exact function successfully but it does not work for me.

If I replace:

emit Transfer(address(this), holders[i], amount);

with :

_transfer(_msgSender(), holders[i], amount);

It works if I use _transfer but then the batch transfer is prohibitively expensive.

I understand that emit Transfer is an event and the _transfer is a function but I have seen others use emit Transfer to move tokens without calling _transfer.

I have seen other people batch transfer tokens with this method as cheap as 4000 tokens at $36 so this is the goal.

Thanks in advance for any suggestions.

Hey @LookyLooky, event emissions won't change the state of the blockchain, they only emit information to the chain logs. You definitely need to be calling the _transfer function (or external transfer or transferFrom functions) in order actually send a balance to your desired recipients and the gas cost will be much greater than a simple event emission.

Also note that within _transfer there is already a Transfer event emitted.

1 Like

BRO DID FIND THE SOLUTION actually i just add the batch transfert to my contract but nothing happend .. can u help me with that

@jimmy-zak20 Please pay attention to the previous comment as it explains why your function and the one in this post do not work.