[Ethereum] In solidity, how can I hardcode bytes > 32 bytes

bytesmemorysolidity

I want to create a contract with a hardcoded bytes variable.

contract Test(){
   function Test(){
      bytes x = 0x..... //greater than 32 bytes 
   }
}

The above returns a Type int_const not implicitly convertible to expected type bytes storage pointer error.

Best Answer

contract C1 {
    function f1() returns(bytes) {
        bytes memory bb = "\x00\x01\x02";  // you can extend this
        return(bb);
    }
}

Tested using online Solidity Browser, output is:

Result: "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000030001020000000000000000000000000000000000000000000000000000000000"
Cost: 25630 gas.