storage

get_context() StorageContext

Gets current storage context.

>>> get_context()       # StorageContext cannot be read outside the blockchain
_InteropInterface
Returns:

the current storage context

Return type:

boa3.builtin.interop.storage.storagecontext.StorageContext

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

get(key: bytes, context: StorageContext = None) bytes

Gets a value from the persistent store based on the given key.

>>> put(b'unit', b'test')
... get(b'unit')
b'test'
>>> get(b'fake_key')
b''
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context

Return type:

bytes

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

try_get(key: bytes, context: StorageContext = None) tuple[bytes, bool]

Gets a value from the persistent store based on the given key and returns whether the value is stored.

>>> put(b'unit', b'test')
... try_get(b'unit')
(b'test', True)
>>> try_get(b'fake_key')
(b'', False)
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context and whether it was actually stored

Return type:

tuple[bytes, bool]

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

get_int(key: bytes, context: StorageContext = None) int

Gets a value as integer from the persistent store based on the given key. It’s equivalent to boa3.builtin.type.helper.to_int(get(key, context))

>>> put_int(b'unit', 5)
... get_int(b'unit')
5
>>> get_int(b'fake_key')
0
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context

Return type:

int

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

try_get_int(key: bytes, context: StorageContext = None) tuple[int, bool]

Gets a value as integer from the persistent store based on the given key and returns whether the value is stored.

>>> put_int(b'unit', 5)
... try_get_int(b'unit')
(5, True)
>>> try_get_int(b'fake_key')
(0, False)
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context and whether it was actually stored

Return type:

tuple[int, bool]

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

get_bool(key: bytes, context: StorageContext = None) bool

Gets a value as boolean from the persistent store based on the given key. It’s equivalent to boa3.builtin.type.helper.to_bool(get(key, context))

>>> put_bool(b'unit', True)
... get_bool(b'unit')
True
>>> get_bool(b'fake_key')
False
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context

Return type:

bool

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

try_get_bool(key: bytes, context: StorageContext = None) tuple[bool, bool]

Gets a value as boolean from the persistent store based on the given key and returns whether the value is stored.

>>> put_bool(b'unit', False)
... try_get_bool(b'unit')
(False, True)
>>> try_get_bool(b'fake_key')
(False, False)
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context and whether it was actually stored

Return type:

tuple[bool, bool]

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

get_str(key: bytes, context: StorageContext = None) str

Gets a value as string from the persistent store based on the given key. It’s equivalent to boa3.builtin.type.helper.to_str(get(key, context))

>>> put_str(b'unit', 'test')
... get_str(b'unit')
'test'
>>> get_str(b'fake_key')
''
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context

Return type:

str

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

try_get_str(key: bytes, context: StorageContext = None) tuple[str, bool]

Gets a value as string from the persistent store based on the given key and returns whether the value is stored.

>>> put_str(b'unit', 'test')
... try_get_str(b'unit')
('test', True)
>>> try_get_str(b'fake_key')
('', False)
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context and whether it was actually stored

Return type:

tuple[str, bool]

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

get_list(key: bytes, context: StorageContext = None) list

Gets a value as list from the persistent store based on the given key. It’s equivalent to boa3.builtin.nativecontract.stdlib.StdLib.deserialize(get(key, context))

>>> put_list(b'unit', [1, 2, '3'])
... get_list(b'unit')
[1, 2, '3']
>>> get_list(b'fake_key')
[]
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context

Return type:

list

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

try_get_list(key: bytes, context: StorageContext = None) tuple[list, bool]

Gets a value as list from the persistent store based on the given key and returns whether the value is stored.

>>> put_list(b'unit', [1, 2, '3'])
... try_get_list(b'unit')
([1, 2, '3'], True)
>>> get_list(b'fake_key')
([], False)
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context and whether it was actually stored

Return type:

tuple[list, bool]

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

get_dict(key: bytes, context: StorageContext = None) dict

Gets a value as dict from the persistent store based on the given key. It’s equivalent to boa3.builtin.nativecontract.stdlib.StdLib.deserialize(get(key, context))

>>> put_dict(b'unit', {'example': 1, 'other_example': 2})
... get_dict(b'unit')
{'example': 1, 'other_example': 2}
>>> get_dict(b'fake_key')
{}
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context

Return type:

dict

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

try_get_dict(key: bytes, context: StorageContext = None) tuple[dict, bool]

Gets a value as dict from the persistent store based on the given key and returns whether the value is stored.

>>> put_dict(b'unit', {'example': 1, 'other_example': 2})
... get_dict(b'unit')
({'example': 1, 'other_example': 2}, True)
>>> get_dict(b'fake_key')
({}, False)
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context and whether it was actually stored

Return type:

tuple[dict, bool]

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

get_object(key: bytes, context: StorageContext = None) Any

Gets a value as object from the persistent store based on the given key. It’s equivalent to boa3.builtin.nativecontract.stdlib.StdLib.deserialize(get(key, context)) Returns an empty struct if not found.

>>> example = SomeClass()
>>> put_object(b'unit', example)
... get_object(b'unit')
SomeClass
>>> get_object(b'fake_key')
object
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context

Return type:

Any

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

try_get_object(key: bytes, context: StorageContext = None) tuple[Any, bool]

Gets a value as dict from the persistent store based on the given key and returns whether the value is stored.

>>> example = SomeClass()
>>> put_object(b'unit', example)
... try_get_object(b'unit')
(SomeClass, True)
>>> get_object(b'fake_key')
(object, False)
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context and whether it was actually stored

Return type:

tuple[Any, bool]

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

get_uint160(key: bytes, context: StorageContext = None) UInt160

Gets a value as UInt160 from the persistent store based on the given key. It’s equivalent UInt160(get(key, context))

>>> put_uint160(b'unit', UInt160(b'0123456789ABCDEFGHIJ'))
... get_uint160(b'unit')
UInt160(0x4a49484746454443424139383736353433323130)
>>> get_uint160(b'fake_key')
UInt160(0x0000000000000000000000000000000000000000)
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context

Return type:

boa3.builtin.type.UInt160

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

try_get_uint160(key: bytes, context: StorageContext = None) tuple[UInt160, bool]

Gets a value as UInt160 from the persistent store based on the given key and returns whether the value is stored.

>>> put_uint160(b'unit', UInt160(b'0123456789ABCDEFGHIJ'))
... try_get_uint160(b'unit')
(UInt160(0x4a49484746454443424139383736353433323130), True)
>>> get_uint160(b'fake_key')
(UInt160(0x0000000000000000000000000000000000000000), False)
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context and whether it was actually stored

Return type:

tuple[boa3.builtin.type.UInt160, bool]

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

get_uint256(key: bytes, context: StorageContext = None) UInt256

Gets a value as UInt256 from the persistent store based on the given key. It’s equivalent UInt256(get(key, context))

>>> put_uint256(b'unit', UInt256(b'0123456789ABCDEFGHIJKLMNOPQRSTUV'))
... get_uint256(b'unit')
UInt256(0x565554535251504f4e4d4c4b4a49484746454443424139383736353433323130)
>>> get_uint160(b'fake_key')
UInt256(0x0000000000000000000000000000000000000000000000000000000000000000)
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context

Return type:

boa3.builtin.type.UInt256

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

try_get_uint256(key: bytes, context: StorageContext = None) tuple[UInt256, bool]

Gets a value as UInt256 from the persistent store based on the given key and returns whether the value is stored.

>>> put_uint256(b'unit', UInt256(b'0123456789ABCDEFGHIJKLMNOPQRSTUV'))
... get_uint256(b'unit')
(UInt256(0x565554535251504f4e4d4c4b4a49484746454443424139383736353433323130), True)
>>> get_uint160(b'fake_key')
(UInt256(0x0000000000000000000000000000000000000000000000000000000000000000), False)
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context and whether it was actually stored

Return type:

tuple[boa3.builtin.type.UInt256, bool]

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

get_ecpoint(key: bytes, context: StorageContext = None) ECPoint

Gets a value as ECPoint from the persistent store based on the given key. It’s equivalent ECPoint(get(key, context))

>>> put_ecpoint(b'unit', ECPoint(b'0123456789ABCDEFGHIJKLMNOPQRSTUVW'))
... get_ecpoint(b'unit')
ECPoint(0x57565554535251504f4e4d4c4b4a49484746454443424139383736353433323130)
>>> get_ecpoint(b'fake_key')
ECPoint(0x000000000000000000000000000000000000000000000000000000000000000000)
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context

Return type:

boa3.builtin.type.ECPoint

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

try_get_ecpoint(key: bytes, context: StorageContext = None) tuple[ECPoint, bool]

Gets a value as ECPoint from the persistent store based on the given key and returns whether the value is stored.

>>> put_ecpoint(b'unit', ECPoint(b'0123456789ABCDEFGHIJKLMNOPQRSTUVW'))
... try_get_ecpoint(b'unit')
(ECPoint(0x57565554535251504f4e4d4c4b4a49484746454443424139383736353433323130), True)
>>> try_get_ecpoint(b'fake_key')
(ECPoint(0x000000000000000000000000000000000000000000000000000000000000000000), False)
Parameters:
  • key (bytes) – value identifier in the store

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Returns:

the value corresponding to given key for current storage context and whether it was actually stored

Return type:

tuple[boa3.builtin.type.ECPoint, bool]

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

get_read_only_context() StorageContext

Gets current read only storage context.

>>> get_context()       # StorageContext cannot be read outside the blockchain
_InteropInterface
Returns:

the current read only storage context

Return type:

boa3.builtin.interop.storage.storagecontext.StorageContext

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

put(key: bytes, value: bytes, context: StorageContext = None)

Inserts a given bytes value in the key-value format into the persistent storage.

>>> put(b'unit', b'test')
None
Parameters:
  • key (bytes) – the identifier in the store for the new value

  • value (bytes) – value to be stored

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

put_int(key: bytes, value: int, context: StorageContext = None)

Inserts a given integer value in the key-value format into the persistent storage. It’s equivalent to put(key, boa3.builtin.type.helper.to_int(value), context)

>>> put_int(b'unit', 5)
None
Parameters:
  • key (bytes) – the identifier in the store for the new value

  • value (int) – value to be stored

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

put_bool(key: bytes, value: bool, context: StorageContext = None)

Inserts a given boolean value in the key-value format into the persistent storage. It’s equivalent to put(key, boa3.builtin.type.helper.to_bool(value), context)

>>> put_bool(b'unit', True)
None
Parameters:
  • key (bytes) – the identifier in the store for the new value

  • value (bool) – value to be stored

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

put_str(key: bytes, value: str, context: StorageContext = None)

Inserts a given str value in the key-value format into the persistent storage. It’s equivalent to put(key, boa3.builtin.type.helper.to_str(value), context)

>>> put_str(b'unit', 'test')
None
Parameters:
  • key (bytes) – the identifier in the store for the new value

  • value (str) – value to be stored

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

put_list(key: bytes, value: list, context: StorageContext = None)

Inserts a given list value in the key-value format into the persistent storage. It’s equivalent to put(key, boa3.builtin.nativecontract.stdlib.serialize(value), context)

>>> put_list(b'unit', [1, 2, '3'])
None
Parameters:
  • key (bytes) – the identifier in the store for the new value

  • value (list) – value to be stored

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

put_dict(key: bytes, value: dict, context: StorageContext = None)

Inserts a given dict value in the key-value format into the persistent storage. It’s equivalent to put(key, boa3.builtin.nativecontract.stdlib.serialize(value), context)

>>> put_dict(b'unit', {'example': 1, 'other_example': 2})
None
Parameters:
  • key (bytes) – the identifier in the store for the new value

  • value (dict) – value to be stored

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

put_object(key: bytes, value: object, context: StorageContext = None)

Inserts a given object value in the key-value format into the persistent storage. It’s equivalent to put(key, boa3.builtin.nativecontract.stdlib.serialize(value), context)

>>> example = SomeClass()
>>> put_object(b'unit', example)
None
Parameters:
  • key (bytes) – the identifier in the store for the new value

  • value (dict) – value to be stored

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

put_uint160(key: bytes, value: UInt160, context: StorageContext = None)

Inserts a given UInt160 value in the key-value format into the persistent storage. It’s equivalent to put(key, value, context) since UInt160 is a subclass of bytes

>>> put_uint160(b'unit', UInt160(b'0123456789ABCDEFGHIJ'))
None
Parameters:
  • key (bytes) – the identifier in the store for the new value

  • value (boa3.builtin.type.UInt160) – value to be stored

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

put_uint256(key: bytes, value: UInt256, context: StorageContext = None)

Inserts a given UInt256 value in the key-value format into the persistent storage. It’s equivalent to put(key, value, context) since UInt256 is a subclass of bytes

>>> put_uint256(b'unit', UInt256(b'0123456789ABCDEFGHIJKLMNOPQRSTUV'))
None
Parameters:
  • key (bytes) – the identifier in the store for the new value

  • value (boa3.builtin.type.UInt256) – value to be stored

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

put_ecpoint(key: bytes, value: ECPoint, context: StorageContext = None)

Inserts a given ECPoint value in the key-value format into the persistent storage. It’s equivalent to put(key, value, context) since ECPoint is a subclass of bytes

>>> put_ecpoint(b'unit', ECPoint(b'0123456789ABCDEFGHIJKLMNOPQRSTUVW'))
None
Parameters:
  • key (bytes) – the identifier in the store for the new value

  • value (boa3.builtin.type.ECPoint) – value to be stored

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

delete(key: bytes, context: StorageContext = None)

Removes a given key from the persistent storage if exists.

>>> put(b'unit', 'test')
... delete()
... get(b'unit')
''
Parameters:
  • key (bytes) – the identifier in the store for the new value

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

find(prefix: bytes, context: StorageContext = None, options: FindOptions = FindOptions.NONE) Iterator

Searches in the storage for keys that start with the given prefix.

>>> put(b'a1', 'one')
... put(b'a2', 'two')
... put(b'a3', 'three')
... put(b'b4', 'four')
... findIterator = find(b'a')
... findResults = []
... while findIterator.next():
...     findResults.append(findIterator.value)
... findResults
['one', 'two', 'three']
Parameters:
  • prefix (bytes) – prefix to find the storage keys

  • context (boa3.builtin.interop.storage.storagecontext.StorageContext) – storage context to be used

  • options (boa3.builtin.interop.storage.findoptions.FindOptions.FindOptions) – the options of the search

Returns:

an iterator with the search results

Return type:

boa3.builtin.interop.iterator.Iterator

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

Subpackages

class FindOptions(value)

Bases: IntEnum

Represents the options you can use when trying to find a set of values inside the storage.

Check out Neo’s Documentation to learn more about the FindOption class.

NONE

No option is set. The results will be an iterator of (key, value).

KEYS_ONLY

Indicates that only keys need to be returned. The results will be an iterator of keys.

REMOVE_PREFIX

Indicates that the prefix byte of keys should be removed before return.

VALUES_ONLY

Indicates that only values need to be returned. The results will be an iterator of values.

DESERIALIZE_VALUES

Indicates that values should be deserialized before return.

PICK_FIELD_0

Indicates that only the field 0 of the deserialized values need to be returned. This flag must be set together with DESERIALIZE_VALUES, e.g., DESERIALIZE_VALUES | PICK_FIELD_0

PICK_FIELD_1

Indicates that only the field 1 of the deserialized values need to be returned. This flag must be set together with DESERIALIZE_VALUES, e.g., DESERIALIZE_VALUES | PICK_FIELD_1

BACKWARDS

Indicates that results should be returned in backwards (descending) order.

StorageContext()

The storage context used to read and write data in smart contracts.

Check out Neo’s Documentation to learn more about the StorageContext class.

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead

StorageMap(context, prefix: bytes)

The key-value storage for the specific prefix in the given storage context.

Check out Neo’s Documentation to learn more about StorageMap.

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.storage instead