ethereum_types.bytes

Sequences of 256-bit values.

B

10
B = TypeVar("B", bound="FixedBytes")

FixedBytes

Superclass for fixed sized byte arrays. Not intended to be used directly, but should be subclassed.

class FixedBytes:

LENGTH

19
    LENGTH: ClassVar[int]

__slots__

24
    __slots__ = ()

__new__

Create a new instance, ensuring the result has the correct length.

def __new__(cls: Type[B], ​​*args: Any, ​​**kwargs: Any) -> B:
27
        """
28
        Create a new instance, ensuring the result has the correct length.
29
        """
30
        result = super(FixedBytes, cls).__new__(cls, *args, **kwargs)
31
        if len(result) != cls.LENGTH:
32
            raise ValueError(
33
                f"expected {cls.LENGTH} bytes but got {len(result)}"
34
            )
35
        return result

zero_bytes

Count and return the number of zero bytes in the byte array.

def zero_bytes(self) -> "Uint":
38
        """
39
        Count and return the number of zero bytes in the byte array.
40
        """
41
        from .numeric import Uint
42
43
        return Uint(self.count(b"\0"))

Bytes0

Byte array of exactly zero elements.

class Bytes0:

LENGTH

51
    LENGTH = 0

Bytes1

Byte array of exactly one elements.

class Bytes1:

LENGTH

62
    LENGTH = 1

Bytes4

Byte array of exactly four elements.

class Bytes4:

LENGTH

73
    LENGTH = 4

Bytes8

Byte array of exactly eight elements.

class Bytes8:

LENGTH

84
    LENGTH = 8

Bytes20

Byte array of exactly 20 elements.

class Bytes20:

LENGTH

95
    LENGTH = 20

Bytes32

Byte array of exactly 32 elements.

class Bytes32:

LENGTH

106
    LENGTH = 32

Bytes48

Byte array of exactly 48 elements.

class Bytes48:

LENGTH

117
    LENGTH = 48

Bytes64

Byte array of exactly 64 elements.

class Bytes64:

LENGTH

125
    LENGTH = 64

Bytes96

Byte array of exactly 96 elements.

class Bytes96:

LENGTH

136
    LENGTH = 96

Bytes256

Byte array of exactly 256 elements.

class Bytes256:

LENGTH

147
    LENGTH = 256

Bytes

Sequence of bytes (octets) of arbitrary length.

153
Bytes = bytes