2

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?

TylerH
  • 20,799
  • 66
  • 75
  • 101
R-J
  • 928
  • 1
  • 7
  • 24
  • Your post says you went through the process “including allowance”. The `allowance` and `approve` functions are two different things. Did you `approve` your airdrop contract to distribute the tokens? – Adam Kipnis Aug 07 '18 at 01:21
  • Yes! Sorry for misunderstanding - with allowance I meant to say that I have approved the token distribution from another address. :) – R-J Aug 07 '18 at 05:18
  • 1
    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). – Adam Kipnis Aug 07 '18 at 05:40
  • Hey @AdamKipnis The 3rd option was the correct one! I was approving the contractOwner not the contract itself. Please add this as an anser, so I can approve it. :) – R-J Aug 07 '18 at 06:10

1 Answers1

2

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

Adam Kipnis
  • 10,175
  • 10
  • 35
  • 48