Solidity – Error Encoding Arguments: Invalid bytes32 Value (arg, coderType, version 4.0.37)

remixsolidity

pragma solidity ^0.4.20;

contract TestBytes32ToString{
    function bytes32ToString(bytes32 x) public pure returns(uint,uint,uint,string memory){
        bytes memory bytesString = new bytes(32);
        uint charCount = 0;
        for(uint i = 0; i < 32; i++){
            byte char = byte(bytes32(uint(x)*2**(8*i)));
            if(char != 0){
                  bytesString[charCount] = char;
                  charCount++;
            }
        }

        bytes memory bytesStringTrimmed = new bytes(charCount);
        for(i = 0; i < charCount; i++){
            bytesStringTrimmed[i] = bytesString[i];
        }
        return (uint(x),uint(x)*2**(8*0),uint(x)*2**(8*1),string(bytesStringTrimmed));
    }
}

When I execute the above code in the new layout of remix,I input "0x6c",then an error had occurred as follws:

Error encoding arguments: Error: invalid bytes32 value (arg="", coderType="bytes32", value="0x6c", version=4.0.37) 

enter image description here

But I did the same operation in the previous version of remix, it works.

enter image description here

Best Answer

That's because the value has to be 32 bytes long in the new layout, like:

0x6c00000000000000000000000000000000000000000000000000000000000000

From remix-ide github:

if you specify bytes32, then the value has to be 32 bytes long. If you don't mean that, you could use a shorter length, the types string or bytes.

Duplicated issue with the same question here.