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.EvmHookMappingEntry;
import java.util.List;
// 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(new HookEntityId(accountId), 1002L);
// 2. Define the mapping update
// We are updating a mapping at Solidity storage slot 0x02.
// The mapping key is an address (0x...1234) and the new value is a boolean (true).
// Mapping Key (e.g., an address)
byte[] mappingKey = new byte[32];
mappingKey[31] = 0x34;
mappingKey[30] = 0x12;
// Mapping Slot (Solidity slot 2)
byte[] mappingSlot = new byte[32];
mappingSlot[31] = 0x02;
// New Value (e.g., a boolean 'true' which is 1)
byte[] newValue = new byte[32];
newValue[31] = 0x01;
// Create the mapping entry
EvmHookMappingEntry mappingEntry = EvmHookMappingEntry.ofKey(mappingKey, newValue);
// Create the mapping update
EvmHookStorageUpdate.EvmHookMappingEntries storageUpdate =
new EvmHookStorageUpdate.EvmHookMappingEntries(
mappingSlot,
List.of(mappingEntry)
);
// 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);