1

I am trying to transfer a token from a token contract. the control reaches till the point where I have the transfer statement later it fails. I do not understand why it is failing. I made sure the account in which I have logged in have sufficient tokens. Could you please assist me to correct the code ?

enter image description here

enter image description here

Code

pragma solidity ^0.4.24;

/**
 * @title Ownable
 * @dev The Ownable contract has an owner address, and provides basic authorization control 
 * functions, this simplifies the implementation of "user permissions". 
 */
contract Ownable {
  address public owner;


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


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


  /**
   * @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 {
    if (newOwner != address(0)) {
      owner = newOwner;
    }
  }

}

contract Token{
  function transfer(address to, uint value) public returns (bool);
}

contract Airdrop1 is Ownable {

    function multisend(address _tokenAddr, address[] _to, uint256[] _value) public
    returns (bool _success) {
        assert(_to.length == _value.length);
        assert(_to.length <= 150);
        // loop through to addresses and send value
        for (uint8 i = 0; i < _to.length; i++) {
                assert((Token(_tokenAddr).transfer(_to[i], _value[i])) == true);
            }
            return true;
        }
}

1 Answer 1

0

The amount of tokens that the account that calls multisend has does not matter. What matters is the amount of tokens that the Airdrop1 contract has, because it tries to transfer tokens. Are you sure it has enough?

An unrelated suggestion: You should probably use uint256 in your for loop instead of uint8. Smaller integers can sometimes cost more gas. Also, uint8 overflows very quickly when you reach 255.

1
  • 1
    You are the man !. Thanks for making me understand this concept !
    – iappmaker
    Dec 12, 2018 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.