Solidity

無法將字節傳遞給函式而不會出錯

  • October 10, 2018

下面的程式碼可以完美編譯並且似乎可以工作,但是當我嘗試呼叫 addTask 時:

“項目1”,1,“i1”,1

我已經嘗試了引號括號,括號的所有可能變化……

但是我收到以下錯誤:

處理 taskListContract.addTask 錯誤:錯誤編碼參數:錯誤:無效字節值(arg="",type=“string”,value=“item1”)

很感謝任何形式的幫助。

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

contract Owned {

   address public owner;

   constructor() public {
       owner = msg.sender;
   }

   /// @notice modifies any function it gets attached to, only allows the owner of the smart contract to execute the function
   modifier onlyOwner(){
       require(msg.sender == owner);
       _;
   }
}

contract taskListContract is Owned {
   struct task {
       bytes iname;
       uint16 taskid;
       bytes icode;
       //replace for a boolean
       uint ivalue;
   }

   uint taskCount;
   mapping(bytes => task) taskList;
   task[] taskArray;

   ///function taskListContract() public {
   ///    log0('hi');
   /// }

   function addTask(bytes name, uint16 iid, bytes code, uint val) external onlyOwner{        
       task memory tasknew = task(name, iid ,code, val);
       // log0(itemnew);
       taskList[code] = tasknew;
       taskArray.push(tasknew);
       taskCount++;
   }

   function countItemList() public constant returns (uint count)  {     
       return taskCount;
   }

   function removeTask(bytes code) external onlyOwner {
       delete taskList[code];
       taskCount--;
   }

   function getTask(bytes code) public constant returns (bytes iname, uint val)  {   
       return (taskList[code].iname, taskList[code].ivalue);
   }
}

為了呼叫帶bytes參數的函式,您需要以十六進制格式傳遞參數

在此處輸入圖像描述

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