Create one or more new entities in GolemBase with specified data and annotations.
Each entity is stored with a configurable BTL (Block-to-Live) that determines when the entity will automatically expire and be removed from the network.
Array of entity creation specifications
Optional
args: {Optional transaction parameters
Optional
gas?: bigintManual gas limit override
Optional
maxFeePerGas?: bigintMaximum fee per gas unit (EIP-1559)
Optional
maxPriorityFeePerGas?: bigintMaximum priority fee per gas unit (EIP-1559)
Optional
txHashCallback?: (txHash: `0x${string}`) => voidCallback invoked with transaction hash when submitted
Promise resolving to an array of creation receipts, each including the new entity key and its expiration block.
const receipts = await client.createEntities([
{
data: new TextEncoder().encode(JSON.stringify({ message: "Hello World" })),
btl: 1000, // Entity expires in 1000 blocks
stringAnnotations: [
new Annotation("type", "greeting"),
new Annotation("version", "1.0")
],
numericAnnotations: [
new Annotation("priority", 1)
]
}
]);
console.log('Created entity:', receipts[0].entityKey);
console.log('Expires at block:', receipts[0].expirationBlock);
Deletes one or more entities from GolemBase permanently.
Only the entity owner can delete their entities. Deleted entities cannot be recovered and their storage is immediately freed on the network.
Array of hexadecimal entity keys to delete
Optional
args: {Optional transaction parameters
Optional
gas?: bigintManual gas limit override
Optional
maxFeePerGas?: bigintMaximum fee per gas unit (EIP-1559)
Optional
maxPriorityFeePerGas?: bigintMaximum priority fee per gas unit (EIP-1559)
Optional
txHashCallback?: (txHash: `0x${string}`) => voidCallback invoked with transaction hash when submitted
A promise that resolves to an array of DeleteEntityReceipt
objects (usually just the deleted keys).
Extends the BTL (Block-to-Live) of one or more entities in GolemBase.
This operation increases the lifetime of entities by adding additional blocks to their expiration time, preventing them from being automatically deleted.
Array of BTL extension specifications
Optional
args: {Optional transaction parameters
Optional
gas?: bigintManual gas limit override
Optional
maxFeePerGas?: bigintMaximum fee per gas unit (EIP-1559)
Optional
maxPriorityFeePerGas?: bigintMaximum priority fee per gas unit (EIP-1559)
Optional
txHashCallback?: (txHash: `0x${string}`) => voidCallback invoked with transaction hash when submitted
A promise resolving to n array of ExtendEntityReceipt
objects, each showing the old and new expiration blocks.
Will throw an error if the transaction fails, entity doesn't exist, or caller lacks permission
const receipts = await client.extendEntities([
{
entityKey: "0x1234567890abcdef...",
numberOfBlocks: 500 // Add 500 more blocks to the entity's lifetime
}
]);
receipts.forEach(receipt => {
console.log(`Entity ${receipt.entityKey}:`);
console.log(` Old expiration: block ${receipt.oldExpirationBlock}`);
console.log(` New expiration: block ${receipt.newExpirationBlock}`);
});
Returns all entity keys stored in GolemBase.
A promise that resolves to an array of entity keys (Hex[]).
Retrieves all entity keys owned by a specific Ethereum address.
The address whose owned entities should be returned.
A promise that resolves to an array of entity keys owned by the address.
Finds all entities that are scheduled to expire at a specific block.
The block number to check against.
A promise that resolves to an array of entity keys expiring at the given block.
Returns the total number of entities stored in GolemBase.
A promise that resolves to the total count of entities.
Retrieves metadata for a given entity key.
The key to retrieve metadata for.
An EntityMetaData object with structured information about the entity.
Get the Ethereum address of the owner of the Ethereum account used by this client
A promise that resolves to the address as a Hex string.
Returns the raw internal client used under the hood. The internal client which exposes low-level methods and also gives access to the raw viem.sh ethereum clients, which allows to call low-level ethereum methods directly
This includes low-level Ethereum client access (via viem.sh). This is considered an advanced feature. Use with caution if you need to make low-level Ethereum calls directly.
The internal client object used by the SDK.
Returns the raw base64-encoded storage value associated with a given entity key.
The entity key to fetch the data for.
A Uint8Array containing the base64 encoded value stored in the entity.
Queries entities in GolemBase using annotations or metadata filters.
A query string in the GolemBase filter syntax.
A promise that resolves to an array of matching entity keys.
Send a combined transaction to GolemBase that can include multiple operations: create, update, delete, and extend operations in a single atomic transaction.
Optional
creates: GolemBaseCreate[]Array of create operations to include in this transaction
Optional
updates: GolemBaseUpdate[]Array of update operations to include in this transaction
Optional
deletes: `0x${string}`[]Array of entity keys to delete in this transaction
Optional
extensions: GolemBaseExtend[]Array of BTL extension operations to include in this transaction
Optional
args: {Optional transaction configuration
Optional
gas?: bigintManual gas limit override for the transaction
Optional
maxFeePerGas?: bigintMaximum fee per gas unit (EIP-1559)
Optional
maxPriorityFeePerGas?: bigintMaximum priority fee per gas unit (EIP-1559)
Optional
txHashCallback?: (txHash: `0x${string}`) => voidCallback function invoked with the transaction hash once submitted
A promise that resolves to an object with arrays of receipts for each type of operation.
const result = await client.sendTransaction(
[{ data: new TextEncoder().encode("create"), btl: 1000, stringAnnotations: [], numericAnnotations: [] }],
[{ entityKey: "0x123...", data: new TextEncoder().encode("update"), btl: 2000, stringAnnotations: [], numericAnnotations: [] }],
["0x456..."],
[{ entityKey: "0x789...", numberOfBlocks: 500 }],
{ txHashCallback: (hash) => console.log('TX Hash:', hash) }
);
Update one or more existing entities in GolemBase with new data and annotations.
Updates replace the entire entity content, including data and annotations. The BTL can also be modified to extend or reduce the entity's lifetime.
Array of entity update specifications containing entity keys and new data
Optional
args: {Optional transaction parameters
Optional
gas?: bigintManual gas limit override
Optional
maxFeePerGas?: bigintMaximum fee per gas unit (EIP-1559)
Optional
maxPriorityFeePerGas?: bigintMaximum priority fee per gas unit (EIP-1559)
Optional
txHashCallback?: (txHash: `0x${string}`) => voidCallback invoked with transaction hash when submitted
A promise that resolves to an array of UpdateEntityReceipt
objects, each including the entity key and its new expiration block.
Will throw an error if the transaction fails, entity doesn't exist, or caller lacks permission
const receipts = await client.updateEntities([
{
entityKey: "0x1234567890abcdef...",
data: new TextEncoder().encode(JSON.stringify({ message: "Updated content" })),
btl: 2000, // Extend lifetime to 2000 blocks
stringAnnotations: [new Annotation("status", "updated")],
numericAnnotations: []
}
]);
Install callbacks that will be invoked for every GolemBase transaction
The starting block, events trigger the callbacks starting from this block
A callback that's invoked whenever entities are created
A callback that's invoked whenever entities are deleted
Optional
onError?: (error: Error) => voidA callback that's invoked whenever there is an error during the processing
A callback that's invoked whenever entities have their BTL extended
A callback that's invoked whenever entitier are updated
Optional
pollingInterval?: numberIn that case of HTTP transport, the polling interval in milliseconds. Defaults to the default polling interval of viem
Optional
transport?: "http" | "websocket"The transport to use, either HTTP or WebSocket (the default)
a callback to cancel the subscription and stop receiving notifications
The GolemBaseClient interface provides both read and write operations for interacting with the Golem Base L2 network.
This client can perform CRUD operations on entities, manage their BTL (Block-to-Live), and handle transactions on the blockchain.
This interface extends the GolemBaseROClient interface, inheriting all its read-only methods.
Example