2

How do I make an empty bytes32 variable in vyper?

@external
def return_empty() -> (bytes32):
    return ("")

2 Answers 2

2

Vyper does not have a concept of None; instead every type has a default value. For the bytes32 type that is 0x0000000000000000000000000000000000000000000000000000000000000000.

You can generate this initial value using empty(), e.g.

empty_bytes32_var: bytes32 = empty(bytes32)

ref: https://vyper.readthedocs.io/en/stable/types.html#initial-values

2

You can use the initial value of a bytes32, which is just EMPTY_BYTES32

@external
def return_empty() -> (bytes32):
    return (EMPTY_BYTES32)
1
  • 1
    UserWarning: EMPTY_BYTES32 is deprecated. Please use empty(bytes32) instead.
    – gosuto
    Commented Dec 2, 2022 at 18:21

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.