Skip to content

Commit d376020

Browse files
hiero hooks draft updates with gaps
Signed-off-by: krystal <56278409+theekrystallee@users.noreply.github.com>
1 parent 86ca9bb commit d376020

File tree

10 files changed

+1776
-172
lines changed

10 files changed

+1776
-172
lines changed

docs.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,8 @@
680680
"hedera/sdks-and-apis/sdks/accounts-and-hbar/update-an-account",
681681
"hedera/sdks-and-apis/sdks/accounts-and-hbar/transfer-cryptocurrency",
682682
"hedera/sdks-and-apis/sdks/accounts-and-hbar/approve-an-allowance",
683+
"hedera/sdks-and-apis/sdks/accounts-and-hbar/create-and-manage-hooks",
684+
"hedera/sdks-and-apis/sdks/accounts-and-hbar/create-a-hookstore-transaction",
683685
"hedera/sdks-and-apis/sdks/accounts-and-hbar/adjust-an-allowance",
684686
"hedera/sdks-and-apis/sdks/accounts-and-hbar/delete-an-account",
685687
"hedera/sdks-and-apis/sdks/accounts-and-hbar/get-account-balance",

hedera/core-concepts/accounts/hiero-hooks.mdx

Lines changed: 286 additions & 69 deletions
Large diffs are not rendered by default.

hedera/networks/mainnet/fees.mdx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,19 @@ All fees are subject to change. The fees below reflect a base price for the tran
134134

135135
### Miscellaneous
136136

137-
| Operations | USD ($) |
138-
| ----------------------------------------------------------------- | ------- |
139-
| BatchTransaction ([HIP-551](https://hips.hedera.com/hip/hip-551)) | $0.001 |
140-
| GetVersionInfo | $0.0001 |
141-
| GetByKey | $0.0001 |
142-
| HookStoreTransaction | $0.005 |
143-
| NodeCreate | $0.001 |
144-
| NodeDelete | $0.001 |
145-
| NodeUpdate | $0.001 |
146-
| PrngTransaction | $0.001 |
147-
| SystemDelete | $0.00 |
148-
| SystemUndelete | $0.00 |
149-
| TransactionGetReceipt | $0.00 |
150-
| TransactionGetRecord | $0.0001 |
137+
| Operations | USD ($) |
138+
| ----------------------------------------------------------------- | ------- |
139+
| Add/Delete/Modify Hooks [(HIP-1195)](https://hips.hedera.com/hip/hip-551) | $1.00 |
140+
| BatchTransaction ([HIP-551](https://hips.hedera.com/hip/hip-551)) | $0.001 |
141+
| GetVersionInfo | $0.0001 |
142+
| GetByKey | $0.0001 |
143+
| Invocation of Hook Program | $0.005 |
144+
| HookStore | $0.005 |
145+
| NodeCreate | $0.001 |
146+
| NodeDelete | $0.001 |
147+
| NodeUpdate | $0.001 |
148+
| PrngTransaction | $0.001 |
149+
| SystemDelete | $0.00 |
150+
| SystemUndelete | $0.00 |
151+
| TransactionGetReceipt | $0.00 |
152+
| TransactionGetRecord | $0.0001 |

hedera/sdks-and-apis/sdks/transactions/create-a-hookstore-transaction.mdx renamed to hedera/sdks-and-apis/sdks/accounts-and-hbar/create-a-hookstore-transaction.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ The signing requirements depend on if an `adminKey` was set when the hook was cr
4343
| `setHookId(<HookId>)` | `HookId` | **Required.** Sets the unique identifier of the EVM Hook whose storage is being updated. |
4444
| `addStorageUpdate(<update>)` | `EvmHookStorageUpdate` | **Optional.** Adds a single storage update (slot or mapping entry) to the transaction. |
4545
| `setStorageUpdates(<updates>)` | `list<EvmHookStorageUpdate>` | **Optional.** Sets the full list of storage updates for the transaction. |
46+
| `getHookId()` | `HookId` | Returns the hook ID for this transaction. |
47+
| `getStorageUpdates()` | `list<EvmHookStorageUpdate>` | Returns the list of storage updates. |
4648

4749
<Note>
48-
`EvmHookStorageUpdate` is an abstract class with two concrete implementations: `EvmHookStorageSlot` for direct slot updates and `EvmHookMappingEntries` for updating entries within a Solidity mapping. See the Hiero Hooks SDK Reference for details.
50+
`EvmHookStorageUpdate` is an abstract class with two concrete implementations: `EvmHookStorageSlot` for direct slot updates and `EvmHookMappingEntries` for updating entries within a Solidity mapping. See [Create and Manage Hooks](/hedera/sdks-and-apis/sdks/accounts-and-hbar/create-and-manage-hooks) for full property details on both types.
4951
</Note>
5052

5153
---
@@ -384,4 +386,4 @@ if err != nil {
384386
fmt.Printf("HookStoreTransaction executed with status: %v\n", receipt.Status)
385387
```
386388

387-
</CodeGroup>
389+
</CodeGroup>

hedera/sdks-and-apis/sdks/accounts-and-hbar/create-an-account.mdx

Lines changed: 130 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ When creating a **new account** using the`AccountCreateTransaction()`API you wil
3232

3333
Accounts have a property, `maxAutoAssociations`, and the property's value determines the maximum number of automatic token associations allowed.
3434

35-
<table><thead><tr><th align="center">Property Value</th><th>Description</th></tr></thead><tbody><tr><td align="center"><code>0</code></td><td>Automatic <strong>token</strong> associations or <strong>token airdrops</strong> are not allowed, and the account must be manually associated with a token. This also applies if the value is less than or equal to <code>usedAutoAssociations</code>.</td></tr><tr><td align="center"><code>-1</code></td><td>Unlimited automatic token associations are allowed, and this is the default for accounts created via <a href="../../../core-concepts/accounts/auto-account-creation">auto account creation</a> and for accounts that began as hollow accounts and are now complete. Accounts with <code>-1</code> can receive new tokens without manually associating them. The sender still pays the <code>maxAutoAssociations</code> fee and initial rent for each association.</td></tr><tr><td align="center"><code>> 0</code></td><td>If the value is a positive number (number greater than 0), the number of automatic token associations an account can have is limited to that number.</td></tr></tbody></table>
35+
| Property Value | Description |
36+
| :---: | --- |
37+
| `0` | Automatic **token** associations or **token airdrops** are not allowed, and the account must be manually associated with a token. This also applies if the value is less than or equal to `usedAutoAssociations`. |
38+
| `-1` | Unlimited automatic token associations are allowed, and this is the default for accounts created via [auto account creation](../../../core-concepts/accounts/auto-account-creation) and for accounts that began as hollow accounts and are now complete. Accounts with `-1` can receive new tokens without manually associating them. The sender still pays the `maxAutoAssociations` fee and initial rent for each association. |
39+
| `> 0` | If the value is a positive number (number greater than 0), the number of automatic token associations an account can have is limited to that number. |
3640

3741
<Info>
3842
The sender pays the `maxAutoAssociations` fee and the rent for the first auto-renewal period for the association. This is in addition to the typical transfer fees. This ensures the receiver can receive tokens without association and makes it a smoother transfer process.
@@ -42,14 +46,33 @@ The sender pays the `maxAutoAssociations` fee and the rent for the first auto-re
4246

4347
#### Methods
4448

45-
<table><thead><tr><th>Method</th><th>Type</th><th>Requirement</th></tr></thead><tbody><tr><td><code>setKey(&#x3C;key>)</code></td><td>Key</td><td>Required</td></tr><tr><td><code>setAlias(&#x3C;alias>)</code></td><td>EvmAddress</td><td>Optional</td></tr><tr><td><code>setInitialBalance(&#x3C;initialBalance>)</code></td><td>HBar</td><td>Optional</td></tr><tr><td><code>setReceiverSignatureRequired(&#x3C;booleanValue>)</code></td><td>boolean</td><td>Optional</td></tr><tr><td><code>setMaxAutomaticTokenAssociations(&#x3C;amount>)</code></td><td>int</td><td>Optional</td></tr><tr><td><code>setStakedAccountId(&#x3C;stakedAccountId>)</code></td><td>AccountId</td><td>Optional</td></tr><tr><td><code>setStakedNodeId(&#x3C;stakedNodeId>)</code></td><td>long</td><td>Optional</td></tr><tr><td><code>setDeclineStakingReward(&#x3C;declineStakingReward>)</code></td><td>boolean</td><td>Optional</td></tr><tr><td><code>setAccountMemo(&#x3C;memo>)</code></td><td>String</td><td>Optional</td></tr><tr><td><code>setAutoRenewPeriod(&#x3C;autoRenewPeriod>)</code></td><td>Duration</td><td>Disabled</td></tr></tbody></table>
49+
| Method | Type | Requirement |
50+
| --- | --- | --- |
51+
| `setKey(<key>)` | Key | Required |
52+
| `setAlias(<alias>)` | EvmAddress | Optional |
53+
| `setInitialBalance(<initialBalance>)` | HBar | Optional |
54+
| `setReceiverSignatureRequired(<booleanValue>)` | boolean | Optional |
55+
| `setMaxAutomaticTokenAssociations(<amount>)` | int | Optional |
56+
| `setStakedAccountId(<stakedAccountId>)` | AccountId | Optional |
57+
| `setStakedNodeId(<stakedNodeId>)` | long | Optional |
58+
| `setDeclineStakingReward(<declineStakingReward>)` | boolean | Optional |
59+
| `setAccountMemo(<memo>)` | String | Optional |
60+
| `setAutoRenewPeriod(<autoRenewPeriod>)` | Duration | Disabled |
61+
| `addHook(<hook>)` | [HookCreationDetails](/hedera/sdks-and-apis/sdks/accounts-and-hbar/create-and-manage-hooks) | Optional |
62+
| `setHooks(<hooks>)` | list\<[HookCreationDetails](/hedera/sdks-and-apis/sdks/accounts-and-hbar/create-and-manage-hooks)> | Optional |
4663

4764
<Warning>
4865
**Account Alias**
4966

5067
If an alias is set during account creation, it becomes [immutable](/hedera/support-and-community/glossary#immutability), meaning it cannot be changed. If you plan to update or rotate keys in the future, do not set the alias at the time of initial account creation. The alias can be set after finalizing all key updates.
5168
</Warning>
5269

70+
<Info>
71+
**Account Hooks ([HIP-1195](https://hips.hedera.com/hip/hip-1195))**
72+
73+
You can attach [Hiero Hooks](/hedera/core-concepts/accounts/hiero-hooks) to an account at creation time using `addHook()`. Hooks are programmable EVM extension points that let you enforce custom validation logic on transfers involving this account. See [Create and Manage Hooks](/hedera/sdks-and-apis/sdks/accounts-and-hbar/create-and-manage-hooks) for full details and utility class reference.
74+
</Info>
75+
5376
<CodeGroup>
5477

5578
```java Java
@@ -159,17 +182,112 @@ println!("The new account ID is {}", new_account_id);
159182

160183
</CodeGroup>
161184

185+
#### Create an account with an EVM hook
186+
187+
This example creates a new account with an [account allowance hook](/hedera/core-concepts/accounts/hiero-hooks) attached. The hook contract must be deployed first via `ContractCreateTransaction`.
188+
189+
<CodeGroup>
190+
191+
```java Java
192+
// Step 1: Deploy hook contract first (standard ContractCreateTransaction)
193+
ContractId contractId = /* ... your deployed hook contract ... */;
194+
195+
// Step 2: Create the hook details
196+
HookCreationDetails hookDetails = new HookCreationDetails()
197+
.setExtensionPoint(HookExtensionPoint.ACCOUNT_ALLOWANCE_HOOK)
198+
.setHookId(1002L)
199+
.setEvmHook(new EvmHook().setContractId(contractId))
200+
.setAdminKey(adminKey.getPublicKey());
201+
202+
// Step 3: Create the account with the hook attached
203+
TransactionResponse txResponse = new AccountCreateTransaction()
204+
.setKey(accountKey.getPublicKey())
205+
.setInitialBalance(Hbar.from(1))
206+
.addHook(hookDetails)
207+
.setMaxTransactionFee(new Hbar(10))
208+
.freezeWith(client)
209+
.sign(accountKey)
210+
.execute(client);
211+
212+
AccountId newAccountId = txResponse.getReceipt(client).accountId;
213+
System.out.println("Account created with hook: " + newAccountId);
214+
```
215+
216+
```javascript JavaScript
217+
import {
218+
AccountCreateTransaction,
219+
HookCreationDetails,
220+
EvmHook,
221+
HookExtensionPoint,
222+
Hbar,
223+
Long,
224+
} from "@hashgraph/sdk";
225+
226+
// Step 1: Deploy hook contract first (standard ContractCreateTransaction)
227+
const contractId = /* ... your deployed hook contract ... */;
228+
229+
// Step 2: Create the hook details
230+
const hookDetails = new HookCreationDetails({
231+
extensionPoint: HookExtensionPoint.ACCOUNT_ALLOWANCE_HOOK,
232+
hookId: Long.fromInt(1002),
233+
evmHook: new EvmHook({ contractId }),
234+
adminKey: adminKey.publicKey,
235+
});
236+
237+
// Step 3: Create the account with the hook attached
238+
const txResponse = await (
239+
await new AccountCreateTransaction()
240+
.setKeyWithoutAlias(accountKey.publicKey)
241+
.setInitialBalance(new Hbar(1))
242+
.addHook(hookDetails)
243+
.setMaxTransactionFee(new Hbar(10))
244+
.freezeWith(client)
245+
.sign(accountKey)
246+
).execute(client);
247+
248+
const { accountId } = await txResponse.getReceipt(client);
249+
console.log(`Account created with hook: ${accountId}`);
250+
```
251+
252+
```go Go
253+
// Step 1: Deploy hook contract first (standard ContractCreateTransaction)
254+
// contractId := ... your deployed hook contract ...
255+
256+
// Step 2: Create the hook details
257+
hookDetails := hook.NewHookCreationDetails().
258+
SetExtensionPoint(hook.AccountAllowanceHook).
259+
SetHookID(1002).
260+
SetEvmHook(hook.NewEvmHook().SetContractID(contractId)).
261+
SetAdminKey(adminKey.PublicKey())
262+
263+
// Step 3: Create the account with the hook attached
264+
txResponse, err := hedera.NewAccountCreateTransaction().
265+
SetKey(accountKey.PublicKey()).
266+
SetInitialBalance(hedera.NewHbar(1)).
267+
AddHook(hookDetails).
268+
SetMaxTransactionFee(hedera.NewHbar(10)).
269+
FreezeWith(client).
270+
Sign(accountKey).
271+
Execute(client)
272+
273+
receipt, err := txResponse.GetReceipt(client)
274+
fmt.Printf("Account created with hook: %v\n", receipt.AccountID)
275+
```
276+
277+
</CodeGroup>
278+
162279
#### Get transaction values
163280

164-
| Method | Type | Description |
165-
| -------------------------------- | --------- | --------------------------------------------------------- |
166-
| `getKey()` | Key | Returns the public key on the account |
167-
| `getInitialBalance()` | Hbar | Returns the initial balance of the account |
168-
| `getAutoRenewPeriod()` | Duration | Returns the auto renew period on the account |
169-
| `getDeclineStakingReward()` | boolean | Returns whether or not the account declined rewards |
170-
| `getStakedNodeId()` | long | Returns the node ID |
171-
| `getStakedAccountId()` | AccountId | Returns the node account ID |
172-
| `getReceiverSignatureRequired()` | boolean | Returns whether the receiver signature is required or not |
281+
| Method | Type | Description |
282+
| --- | --- | --- |
283+
| `getKey()` | Key | Returns the public key on the account |
284+
| `getInitialBalance()` | Hbar | Returns the initial balance of the account |
285+
| `getAutoRenewPeriod()` | Duration | Returns the auto renew period on the account |
286+
| `getDeclineStakingReward()` | boolean | Returns whether or not the account declined rewards |
287+
| `getStakedNodeId()` | long | Returns the node ID |
288+
| `getStakedAccountId()` | AccountId | Returns the node account ID |
289+
| `getReceiverSignatureRequired()` | boolean | Returns whether the receiver signature is required or not |
290+
| `getHooks()` | list\<HookCreationDetails> | Returns the hooks to be created with the account |
173291

174292
<CodeGroup>
175293

@@ -213,4 +331,4 @@ AccountCreateTransaction := hedera.NewAccountCreateTransaction().
213331
accountKey, err := AccountCreateTransaction.GetKey()
214332
```
215333

216-
</CodeGroup>
334+
</CodeGroup>

0 commit comments

Comments
 (0)