import (
"fmt"
hedera "github.com/hiero-ledger/hiero-sdk-go/v2/sdk"
)
// Assume these variables are defined:
// var client *client.Client // e.g., client.ClientForTestnet()
// var accountID account.AccountID // e.g., account.AccountID{Shard: 0, Realm: 0, Account: 1000}
// var adminKey *crypto.PrivateKey // The hook's admin key
// 1. Define the target hook ID
hookID := hedera.NewHookId(
*hedera.NewHookEntityIdWithAccountId(accountID),
1002,
)
// 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)
mappingKey := make([]byte, 32)
mappingKey[31] = 0x34
mappingKey[30] = 0x12
// Mapping Slot (Solidity slot 2)
mappingSlot := make([]byte, 32)
mappingSlot[31] = 0x02
// New Value (e.g., a boolean 'true' which is 1)
mappingValue := make([]byte, 32)
mappingValue[31] = 0x01
// Create the mapping entry
mappingEntry := hedera.NewEvmHookMappingEntryWithKey(mappingKey, mappingValue)
mappingEntries := hedera.NewEvmHookMappingEntries().
SetMappingSlot(mappingSlot).
AddMappingEntry(*mappingEntry)
// 3. Create and execute the HookStoreTransaction
hookStoreTx := hedera.NewHookStoreTransaction().
SetHookId(*hookID).
AddStorageUpdate(mappingEntries).
FreezeWith(client)
// Must be signed by the hook's admin key
response, err := hookStoreTx.Sign(adminKey).Execute(client)
if err != nil {
// Handle error
}
// Get the receipt
receipt, err := response.GetReceipt(client)
if err != nil {
// Handle error
}
fmt.Printf("HookStoreTransaction executed with status: %v\n", receipt.Status)