R-J
R-J

Reputation: 936

Airdrop contract not working -- VM error: revert

I am trying to implement this Airdrop: https://github.com/odemio/airdropper/blob/master/Airdropper.sol Initially, I started writing tests for our use-case, but the airdrop was not working.

function airdrop(address source, address[] dests, uint[] values) public onlyOwner {
    // This simple validation will catch most mistakes without consuming
    // too much gas.
    require(dests.length == values.length);

    for (uint256 i = 0; i < dests.length; i++) {
        require(token.transferFrom(source, dests[i], values[i].mul(multiplier)));
    }
}

Then I moved to Remix to go through the whole airdrop process, including our Contract deployment, token minting and allowance.

In Remix debugger I found out that the issue is on the line require(token.transferFrom(source, dests[i], values[i].mul(multiplier)));

I also tested the transferFrom function directly on our contract using the same values on Remix.

The error I get when trying to airdrop is:

transact to Airdrop.airdrop errored: VM error: revert.
revert The transaction has been reverted to the initial state.
Note: The constructor should be payable if you send value. Debug the transaction to get more information.

What could cause this issue and how can I debug this further?

Upvotes: 2

Views: 503

Answers (1)

Adam Kipnis
Adam Kipnis

Reputation: 10991

The error could be for several reasons:

  1. source doesn’t have enough tokens to cover all of the transfers.
  2. One or more destination addresses are invalid.
  3. The approve wasn’t done correctly (it’s the airdrop contract that needs to be approved, not the initiator of the transaction).

You can narrow it down by removing the require and see if any drops are successful (the way you have it coded, one failure will roll back the entire transaction).

Upvotes: 2

Related Questions