13

I tried this

contract MyContract{
    bytes public data = 0x3333;

    function clearData(){
         data = 0x;
    }
}

But solc doesn't like me trying to set data to 0x

14

Use "".

contract MyContract{
    bytes public data = "0x3333";
    bytes public empty;

    function clearData(){
         data = "";
    }
}

Tested using https://ethereum.github.io/browser-solidity by looking at the value of data and empty.

  • 3
    Thanks @AakilFernandes for helping build up a knowledgebase for all! – eth Jun 30 '16 at 7:04
2

delete data;

Source http://solidity.readthedocs.io/en/develop/types.html

delete a assigns the initial value for the type to a. I.e. for integers it is equivalent to a = 0, but it can also be used on arrays, where it assigns a dynamic array of length zero or a static array of the same length with all elements reset. For structs, it assigns a struct with all members reset.

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.