stdlib

class StdLib

Bases: object

A class used to represent StdLib native contract

hash: boa3.builtin.type.UInt160
classmethod serialize(item: Any)bytes

Serializes the given value into its bytes representation.

Parameters

item (Any) – value to be serialized

Returns

the serialized value

Return type

bytes

Raises

Exception – raised if the item’s type is not serializable.

classmethod deserialize(data: bytes)Any

Deserializes the given bytes value.

Parameters

data (bytes) – serialized value

Returns

the deserialized result

Return type

Any

Raises

Exception – raised when the date doesn’t represent a serialized value.

classmethod json_serialize(item: Any)str

Serializes an item into a json.

Parameters

item (Any) – The item that will be serialized

Returns

The serialized item

Return type

str

Raises

Exception – raised if the item is an integer value out of the Neo’s accepted range, is a dictionary with a bytearray key, or isn’t serializable.

classmethod json_deserialize(json: str)Any

Deserializes a json into some valid type.

Parameters

json (str) – A json that will be deserialized

Returns

The deserialized json

Return type

Any

Raises

Exception – raised if jsons deserialization is not valid.

classmethod base64_decode(key: str)bytes

Decodes a string value encoded with base64.

Parameters

key (str) – string value to be decoded

Returns

the decoded string

Return type

bytes

classmethod base64_encode(key: bytes)str

Encodes a bytes value using base64.

Parameters

key (bytes) – bytes value to be encoded

Returns

the encoded string

Return type

str

classmethod base58_decode(key: str)bytes

Decodes a string value encoded with base58.

Parameters

key (str) – string value to be decoded

Returns

the decoded bytes

Return type

bytes

classmethod base58_encode(key: bytes)str

Encodes a bytes value using base58.

Parameters

key (bytes) – bytes value to be encoded

Returns

the encoded string

Return type

str

classmethod base58_check_decode(key: str)bytes

Converts the specified str, which encodes binary data as base-58 digits, to an equivalent bytes value. The encoded str contains the checksum of the binary data.

Parameters

key (str) – string value to be decoded

Returns

the decoded bytes

Return type

bytes

classmethod base58_check_encode(key: bytes)str

Converts a bytes value to its equivalent str representation that is encoded with base-58 digits. The encoded str contains the checksum of the binary data.

Parameters

key (bytes) – bytes value to be encoded

Returns

the encoded string

Return type

str

classmethod itoa(value: int, base: int = 10)str

Converts the specific type of value to a decimal or hexadecimal string. The default is decimal.

Parameters
  • value (int) – the int value

  • base (int) – the value’s base

Returns

the converted string

Return type

int

classmethod atoi(value: str, base: int = 10)int

Converts a character string to a specific base value, decimal or hexadecimal. The default is decimal.

Parameters
  • value (str) – the int value as a string

  • base (int) – the value base

Returns

the equivalent value

Return type

int

Raises

Exception – raised when base isn’t 10 or 16.

classmethod memory_compare(mem1: Union[bytes, str], mem2: Union[bytes, str])int

Compares a memory with another one.

Parameters
  • mem1 (bytes or str) – a memory to be compared to another one

  • mem2 (bytes or str) – a memory that will be compared with another one

Returns

-1 if mem1 precedes mem2, 0 if mem1 and mem2 are equal, 1 if mem1 follows mem2

Return type

int

Searches for a given value in a given memory.

Parameters
  • mem (bytes or str) – the memory

  • value (bytes or str) – the value

  • start (int) – the index the search should start from

  • backward (bool) – whether it should invert the memory

Returns

the index of the value in the memory. Returns -1 if it’s not found

Return type

int