22

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

2 Answers 2

24

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.

1
  • 3
    Thanks @AakilFernandes for helping build up a knowledgebase for all!
    – eth
    Commented Jun 30, 2016 at 7:04
3

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 and acknowledge you have read our privacy policy.

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