2

I have deployed a Crowdsale contract and now I need to send my Tokens to a list of addresses using remix and injected web3. I am using below code for Airdrop but when I send tokens to multiple contracts, then I faced the same error i.e "Gas Estimation Failed". Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?

I am using the following parameters on Ropsten Test net:

"0xc7B64B7F81EC1A6692B747697425C0f7d30F5f37",["0x5bd6a15D5DB703e1C498Ec8B6f79839F1bA491e7","0xE4D4aaD83EF6b27bd91Dd9E16Ee3BfF4CB04dd6c"],["100000000000000000000","200000000000000000000"]

Sending 100 tokens to first Address and 200 tokens to second address. Any help will be appreciable.

   contract ERC20 {
      function transfer(address _recipient, uint256 _value) public returns (bool success);
    }


contract Ownable {
  address public owner;


  event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);


  /**
   * @dev The Ownable constructor sets the original `owner` of the contract to the sender
   * account.
   */
  function Ownable() public {
    owner = msg.sender;
  }


  /**
   * @dev Throws if called by any account other than the owner.
   */
  modifier onlyOwner() {
    require(msg.sender == owner);
    _;
  }


  /**
   * @dev Allows the current owner to transfer control of the contract to a newOwner.
   * @param newOwner The address to transfer ownership to.
   */
  function transferOwnership(address newOwner) public onlyOwner {
    require(newOwner != address(0));
    OwnershipTransferred(owner, newOwner);
    owner = newOwner;
  }

}

contract Airdrop is Ownable {

  function distributeBulk(ERC20 token, address[] recipients, uint256[] values) onlyOwner public {
    for (uint256 i = 0; i < recipients.length; i++) {
      token.transfer(recipients[i], values[i]);
    }
  }

  function distribute(ERC20 token, address recipient, uint256 value) onlyOwner public {
      token.transfer(recipient, value);
  }
}
  • Did you first transfer the tokens to the contract? The contract is using transfer so it assumes you first have given the contract a token balance. – pabloruiz55 Aug 18 '18 at 3:34
  • FYI - Its generally NOT advised to push tokens out, since any address could potentially be a contract; and contracts can be purposefully designed (using their default function) to consume ALL gas when receiving ETH. This will make your Airdrop very difficult to execute with a few bad actors. Better to allow your Airdrop group to PULL their tokens out from your contract. – nyusternie Aug 18 '18 at 5:33
  • @pabloruiz55: I was looking for some way to transfer tokens to this contract. As I have already deployed my crowdsale contract which contains all my tokens. Do I need to generate more tokens from another contract and then send to this airdrop contact? Or is there any way to transfer tokens from my crowdsale contract to this airdrop contract? Any suggestions – usman mehmood Aug 20 '18 at 19:20
  • @usmanmehmood I have similar error. Are you able to send tokens to contract by hand? ethereum.stackexchange.com/questions/56993/… – Sigrlami Aug 21 '18 at 10:00
  • @nyusternie can you give an example of how you pull tokens? – Sigrlami Aug 21 '18 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.