Skip to content

Reading an entity

To read an entity, start by creating one by following the instructions here.

Then use the following code; paste in your entity hash when asked via the input() (including the initial 0x):

import asyncio
import anyio
from golem_base_sdk import ( Annotation, GolemBaseClient, GolemBaseCreate, GenericBytes )

async def main() -> None:
    with open('./private.key', 'rb') as private_key_file:
        key_bytes = private_key_file.read(32)

    client = await GolemBaseClient.create_rw_client(
        rpc_url='https://kaolin.holesky.golem-base.io/rpc',
        ws_url='wss://kaolin.holesky.golem-base.io/rpc/ws',
        private_key=key_bytes,
    )

    hash = input('Please paste in your entity hash: ')

    value = await client.get_storage_value(GenericBytes.from_hex_string(hash))

    print(value)

    await client.disconnect()

if __name__ == "__main__":
    asyncio.run(main())

Tip: Notice that you need to first convert the hash string to an instance of GenericBytes by calling its from_hex_string.

If you try to pass the string directly into get_storage_value, you'll receive an error like so:

AttributeError: 'str' object has no attribute 'as_hex_string'

TODO: Let's consider catching this error and throwing a new error that explains that you can't pass a hex string into the function.

OR

Let's have it check the type, see if it's a hex string, and if so, convert it to GenericBytes