I found some code snippets using the 'hex' prefix before a string in a bytes variable. I can't seem to find its description in the solidity docs.

bytes memory bytesVar = "0x01";
bytes memory bytesVarWithHex = hex"01";

When I log the results they return 0x30783031 and 0x01, respectively. What exactly is it doing for the variables being stored?

1 Answer 1


bytes memory bytesVar = "0x01"; is converting the literal string "0x01" to UTF-8 and storing that, and bytes memory bytesVarWithHex = hex"01"; is storing the hex number 1

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.