Solidity

令牌轉移不起作用

  • December 12, 2018

我正在嘗試從代幣合約中轉移代幣。控制一直到我有轉移語句的時候它失敗了。我不明白為什麼它失敗了。我確保我登錄的帳戶有足夠的令牌。你能幫我更正程式碼嗎?

在此處輸入圖像描述

在此處輸入圖像描述

程式碼

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;
       }
}

呼叫的帳戶multisend擁有的代幣數量無關緊要。重要的是Airdrop1合約擁有的代幣數量,因為它試圖轉移代幣。你確定它夠了嗎?

一個不相關的建議:您可能應該uint256for循環中使用而不是uint8. 較小的整數有時會花費更多的氣體。此外,uint8當你到達時很快溢出255

引用自:https://ethereum.stackexchange.com/questions/63975