1

The code below compiles perfectly and seems to work, however when I try to call addTask like:

"item1", 1, "i1", 1

I have tried every possible variation of quotes parenthesis, brackets...

However I get the following error:

transact to taskListContract.addTask errored: Error encoding arguments: Error: invalid bytes value (arg="", type="string", value="item1")

Any help is very much appreciated.

/**
 * @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);
    }
}
1

In order to call function with bytes parameter, you need to pass parameter in hexadecimal format

enter image description here

Your Answer

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

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