Change and delete entities
After you create an entity, you can patch its columns, hand it to another account, or delete it. Only the owner can do any of these. The examples on this page use the Posts schema and clients from your first entity.
Patch columns
Section titled “Patch columns”patchEntity changes the columns you name and leaves the rest as they are. set writes new values, and unset removes optional columns:
import { dec } from "@arkiv-network/sdk/schema"
await walletClient.patchEntity(Posts, entityKey, { set: { score: dec("4.7"), summary: "Updated with new numbers" },})await walletClient.patchEntity(Posts, entityKey, { unset: ["summary"] })The patch is typed by the schema. Unsetting a required column, or setting a value of the wrong type, is a compile error.
A patch throws before it sends anything when:
EmptyPatchError: it has nothing to set or unsetConflictingMutationError: the same column is in bothsetandunset
An entity created with the readonly flag can’t be patched.
Hand an entity to another account
Section titled “Hand an entity to another account”changeOwnership makes another account the owner. From then on, only the new owner can change the entity:
await walletClient.changeOwnership({ entityKey, newOwner: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",})The entity’s $creator stays the account that created it.
Delete an entity
Section titled “Delete an entity”deleteEntity removes an entity before it expires:
await walletClient.deleteEntity({ entityKey })Once the transaction is in a block, the entity is gone, as if it had expired.
Handle failures
Section titled “Handle failures”The node rejects an operation from an account that isn’t the owner, or on an entity that doesn’t exist or has expired. The SDK throws EntityMutationError with the reason:
import { EntityMutationError } from "@arkiv-network/sdk"
try { await walletClient.deleteEntity({ entityKey })} catch (error) { if (error instanceof EntityMutationError) console.error(error.message)}