import com.hedera.hashgraph.sdk.HookStoreTransaction;
import com.hedera.hashgraph.sdk.HookId;
import com.hedera.hashgraph.sdk.HookEntityId;
import com.hedera.hashgraph.sdk.EvmHookStorageUpdate;
import com.hedera.hashgraph.sdk.EvmHookStorageSlot;
// Assume these variables are defined:
// AccountId accountId = AccountId.fromString("0.0.1000");
// PrivateKey adminKey = PrivateKey.fromString("..."); // The hook's admin key
// 1. Define the target hook ID
HookId hookIdObj = new HookId()
.setEntityId(new HookEntityId().setAccountId(accountId))
.setHookId(1002L);
// 2. Define the new storage update
// We are updating storage slot 0x01 with a new value (0x02)
EvmHookStorageUpdate storageUpdate = new EvmHookStorageUpdate()
.setStorageSlot(
new EvmHookStorageSlot()
.setKey(new byte[32]) // 32-byte key for slot 1
.setValue(new byte[32]) // 32-byte new value
);
// Set the actual key and value bytes
storageUpdate.getStorageSlot().setKey(new byte[] {0x01, 0x00, /* ... 30 more zeros */ });
storageUpdate.getStorageSlot().setValue(new byte[] {0x02, 0x00, /* ... 30 more zeros */ });
// 3. Create and execute the HookStoreTransaction
HookStoreTransaction hookStoreTx = new HookStoreTransaction()
.setHookId(hookIdObj)
.addStorageUpdate(storageUpdate)
.freezeWith(client)
.sign(adminKey); // Must be signed by the hook's admin key
TransactionResponse result = hookStoreTx.execute(client);
System.out.println("HookStoreTransaction executed with ID: " + result.transactionId);