Skip to content

Commit 28ddb88

Browse files
AyushBherwani1998“AyushBherwani1998”alexandratranHalleys123shahbaz17
authored
Update for v0.13 release
* Add delegation scopes guide * add delegation scopes guide * minor edits and rename files * add delegation scopes to manual sidebar * restructure and edit * edit to include scopes in guides * address reviewer comments --------- Co-authored-by: “AyushBherwani1998” <“[email protected]”> Co-authored-by: Alexandra Tran <[email protected]> * Update dtk tutorial for v0.13 * Update creating delegation references for v0.13 * Minor DTK fixes (#2277) * Minor DTK fixes * Apply suggestions from code review Co-authored-by: Ayush Bherwani <[email protected]> --------- Co-authored-by: Ayush Bherwani <[email protected]> * Fix broken links (#2278) * update execute on smart accounts behalf guide * add parameters in delegation scopes * update reference docs * update guide: execute-on-smart-accounts-behalf * Apply suggestions from code review Co-authored-by: Alexandra Carrillo <[email protected]> --------- Co-authored-by: Alexandra Carrillo <[email protected]> Co-authored-by: AyushBherwani1998 <“[email protected]”> * Update caveats to use new declarative format * update execution modes * update parametes of caveats to new caveat configs * update caveats api reference to new declarative format * Apply suggestions from code review Co-authored-by: Alexandra Carrillo <[email protected]> * improve docs --------- Co-authored-by: AyushBherwani1998 <“[email protected]”> Co-authored-by: Alexandra Carrillo <[email protected]> * Adds guide: Check the delegation state * add check delegation state guide * fix typos * minor edits --------- Co-authored-by: AyushBherwani1998 <“[email protected]”> Co-authored-by: Alexandra Tran <[email protected]> * Adds guide: Constrain a scope * add constrain a scope documentation * edit guide and fix links * minor edits --------- Co-authored-by: AyushBherwani1998 <“[email protected]”> Co-authored-by: Alexandra Tran <[email protected]> * Update reference section * restructure reference docs * add support for caveat enforcer client reference * add delegation api index page, fix links, adjust toc style * revert toc code font size --------- Co-authored-by: AyushBherwani1998 <“[email protected]”> Co-authored-by: Alexandra Tran <[email protected]> * Update docs to use signer * update to use signer * revert the ref changes * apply reviewer suggestion Co-authored-by: Alexandra Carrillo <[email protected]> --------- Co-authored-by: AyushBherwani1998 <“[email protected]”> Co-authored-by: Alexandra Carrillo <[email protected]> * Add DTK tutorial for creating an invite link (#2289) * Fix typos Co-authored-by: AyushBherwani1998 <“[email protected]”> * Update react-native.md (#2225) useSDK is now modified and connect, terminate options have moved to sdk object inside useSDK function Co-authored-by: Mohammad Shahbaz Alam <[email protected]> * Add DTK tutorial for creating an invite link * Edit the Angular SDK content. (#2287) Signed-off-by: bgravenorst <[email protected]> * Fix deeplink urls (#2293) * Edit the embedded wallets React builder component. (#2292) * Edit the React builder component. Signed-off-by: bgravenorst <[email protected]> * Typo. Signed-off-by: bgravenorst <[email protected]> --------- Signed-off-by: bgravenorst <[email protected]> * update tutorial * Add DTK tutorial for creating an invite link * Update react-native.md (#2225) useSDK is now modified and connect, terminate options have moved to sdk object inside useSDK function Co-authored-by: Mohammad Shahbaz Alam <[email protected]> * Edit the Angular SDK content. (#2287) Signed-off-by: bgravenorst <[email protected]> * Fix deeplink urls (#2293) * update tutorial * Edit the embedded wallets React builder component. (#2292) * Edit the React builder component. Signed-off-by: bgravenorst <[email protected]> * Typo. Signed-off-by: bgravenorst <[email protected]> --------- Signed-off-by: bgravenorst <[email protected]> * add wagmi step and adjust headings * address reviewer comments * address reviewer comments * minor edits --------- Signed-off-by: bgravenorst <[email protected]> Co-authored-by: Ayush Bherwani <[email protected]> Co-authored-by: AyushBherwani1998 <“[email protected]”> Co-authored-by: Arnav Chhabra <[email protected]> Co-authored-by: Mohammad Shahbaz Alam <[email protected]> Co-authored-by: Byron Gravenorst <[email protected]> * revert the ew changes * revert ew change * v0.13 changes * v0.13 changes * Apply suggestions from code review Co-authored-by: Alexandra Carrillo <[email protected]> --------- Co-authored-by: Ayush Bherwani <“[email protected]”> Co-authored-by: Alexandra Carrillo <[email protected]> * minor edits * remove todo * use disallows instead of disables * remove 7715 card from intro page * improve delegation scope ref description * add getMultiTokenPeriodEnforcerAvailableAmount action --------- Signed-off-by: bgravenorst <[email protected]> Co-authored-by: “AyushBherwani1998” <“[email protected]”> Co-authored-by: Alexandra Tran <[email protected]> Co-authored-by: Alexandra Carrillo <[email protected]> Co-authored-by: Arnav Chhabra <[email protected]> Co-authored-by: Mohammad Shahbaz Alam <[email protected]> Co-authored-by: Byron Gravenorst <[email protected]>
1 parent c7504b4 commit 28ddb88

40 files changed

+2622
-1042
lines changed

delegation-toolkit/concepts/delegation/caveat-enforcers.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,23 @@ This "all-or-nothing" approach ensures that delegations only execute exactly as
118118

119119
## Caveat builder
120120

121-
While caveat enforcers operate at the smart contract level, most developers interact with them through the [`CaveatBuilder`](../../guides/delegation/restrict-delegation.md) interface in the MetaMask Delegation Toolkit.
121+
While caveat enforcers operate at the smart contract level, most developers interact with them through the `CaveatBuilder` interface in the MetaMask Delegation Toolkit.
122122

123123
The `CaveatBuilder` provides a developer-friendly TypeScript API that:
124124

125125
- Abstracts away the complexity of correctly formatting and encoding caveat terms.
126126
- Provides type-checking and validation for caveat parameters.
127127
- Handles the creation of the `caveats` array needed when creating a delegation.
128128

129-
Each [caveat type](../../reference/caveats.md) in the `CaveatBuilder`
129+
Each [caveat type](../../reference/delegation/caveats.md) in the `CaveatBuilder`
130130
corresponds to a specific caveat enforcer contract. For example, when you use:
131131

132132
```typescript
133133
caveatBuilder.addCaveat("allowedTargets", ["0xc11F3a8E5C7D16b75c9E2F60d26f5321C6Af5E92"]);
134134
```
135135

136136
The builder is creating a caveat that references the
137-
[`AllowedTargetsEnforcer`](../../reference/caveats.md#allowedtargets) contract address and
137+
[`AllowedTargetsEnforcer`](../../reference/delegation/caveats.md#allowedtargets) contract address and
138138
properly encodes the provided addresses as terms for that enforcer.
139139

140140
## Caveat enforcer best practices
@@ -144,14 +144,14 @@ When designing delegations with caveats, consider these best practices:
144144
- **Combine caveat enforcers appropriately** - Use multiple caveat enforcers to create comprehensive restrictions.
145145

146146
- **Consider caveat enforcer order** - When using caveat enforcers that modify external contract states, the order matters.
147-
For example, using [`NativeTokenPaymentEnforcer`](../../reference/caveats.md#nativetokenpayment) before
148-
[`NativeBalanceChangeEnforcer`](../../reference/caveats.md#nativebalancechange) might cause validation failures.
147+
For example, using [`NativeTokenPaymentEnforcer`](../../reference/delegation/caveats.md#nativetokenpayment) before
148+
[`NativeBalanceChangeEnforcer`](../../reference/delegation/caveats.md#nativebalancechange) might cause validation failures.
149149

150150
- **Be careful with unbounded delegations** - Always include appropriate caveat enforcers to limit what a delegate can do.
151151

152152
## Available caveat enforcers
153153

154-
The Delegation Toolkit provides [out-of-the-box caveat enforcers](../../reference/caveats.md)
154+
The Delegation Toolkit provides [out-of-the-box caveat enforcers](../../reference/delegation/caveats.md)
155155
for common restriction patterns, including:
156156

157157
- Limiting target addresses and methods.

delegation-toolkit/concepts/delegation/index.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,28 @@ You can create the following delegation types:
3939
In a chain of delegations, the first delegation is the root delegation.
4040
For example, Alice delegates the ability to spend her USDC to Bob, limiting the amount to 100 USDC.
4141

42-
Use [`createDelegation`](../../reference/api/delegation.md#createdelegation) to create a root delegation.
42+
Use [`createDelegation`](../../reference/delegation/index.md#createdelegation) to create a root delegation.
4343

4444
- **Open root delegation** - An open root delegation is a root delegation that doesn't specify a delegate.
4545
This means that any account can redeem the delegation.
4646
For example, Alice delegates the ability to spend 100 of her USDC to anyone.
4747

4848
You must create open root delegations carefully, to ensure that they are not misused.
49-
Use [`createOpenDelegation`](../../reference/api/delegation.md#createopendelegation) to create an open root delegation.
49+
Use [`createOpenDelegation`](../../reference/delegation/index.md#createopendelegation) to create an open root delegation.
5050

5151
- **Redelegation** - A delegate can redelegate permissions that have been granted to them, creating a chain of delegations across trusted parties.
5252
For example, Alice delegates the ability to spend 100 of her USDC to Bob.
5353
Bob redelegates the ability to spend 50 of Alice's 100 USDC to Carol.
5454

55-
Use [`createDelegation`](../../reference/api/delegation.md#createdelegation) to create a redelegation.
55+
Use [`createDelegation`](../../reference/delegation/index.md#createdelegation) to create a redelegation.
5656

5757
- **Open redelegation** - An open redelegation is a redelegation that doesn't specify a delegate.
5858
This means that any account can redeem the redelegation.
5959
For example, Alice delegates the ability to spend 100 of her USDC to Bob.
6060
Bob redelegates the ability to spend 50 of Alice's 100 USDC to anyone.
6161

6262
As with open root delegations, you must create open redelegations carefully, to ensure that they are not misused.
63-
Use [`createOpenDelegation`](../../reference/api/delegation.md#createopendelegation) to create an open redelegation.
63+
Use [`createOpenDelegation`](../../reference/delegation/index.md#createopendelegation) to create an open redelegation.
6464

6565
## Delegation Framework
6666

@@ -79,7 +79,7 @@ It consists of the following components:
7979
- **Delegation Manager** - The Delegation Manager validates delegations and triggers executions
8080
on behalf of the delegator, ensuring tasks are executed accurately and securely.
8181

82-
When you redeem a delegation using [`redeemDelegations`](../../reference/api/delegation.md#redeemdelegations), the Delegation Manager performs the following steps.
82+
When you redeem a delegation using [`redeemDelegations`](../../reference/delegation/index.md#redeemdelegations), the Delegation Manager performs the following steps.
8383
It processes a single step for all redemptions before proceeding to the next one:
8484

8585
1. Validates the input data by ensuring the lengths of `delegations`, `modes`, and
@@ -150,30 +150,30 @@ sequenceDiagram
150150

151151
## Execution modes
152152

153-
When redeeming a delegation using [`redeemDelegations`](../../reference/api/delegation.md#redeemdelegations), you must pass an execution mode for each delegation chain you pass to the method.
153+
When redeeming a delegation using [`redeemDelegations`](../../reference/delegation/index.md#redeemdelegations), you must pass an execution mode for each delegation chain you pass to the method.
154154
The Delegation Toolkit supports the following execution modes, based on [ERC-7579](https://erc7579.com/):
155155

156156
| Execution mode | Number of delegation chains passed to `redeemDelegations` | Processing method | Does user operation continue execution if redemption reverts? |
157157
|--|--|--|--|
158-
| `SINGLE_DEFAULT_MODE` | One | Sequential | No |
159-
| `SINGLE_TRY_MODE` | One | Sequential | Yes |
160-
| `BATCH_DEFAULT_MODE` | Multiple | Interleaved | No |
161-
| `BATCH_TRY_MODE` | Multiple | Interleaved | Yes |
158+
| `SingleDefault` | One | Sequential | No |
159+
| `SingleTry` | One | Sequential | Yes |
160+
| `BatchDefault` | Multiple | Interleaved | No |
161+
| `BatchTry` | Multiple | Interleaved | Yes |
162162

163163
### Sequential processing
164164

165-
In `SINGLE` modes, processing is sequential:
165+
In `Single` modes, processing is sequential:
166166

167167
1. For each delegation in the chain, all caveats' `before` hooks are called.
168168
2. The single redeemed action is executed.
169169
3. For each delegation in the chain, all caveats' `after` hooks are called.
170170

171171
### Interleaved processing
172172

173-
In `BATCH` modes, processing is interleaved:
173+
In `Batch` modes, processing is interleaved:
174174

175175
1. For each chain in the batch, and each delegation in the chain, all caveats' `before` hooks are called.
176176
2. Each redeemed action is executed.
177177
3. For each chain in the batch, and each delegation in the chain, all caveats' `after` hooks are called.
178178

179-
`BATCH` mode allows for powerful use cases, but the Delegation Framework currently does not include any `BATCH` compatible caveat enforcers.
179+
`Batch` mode allows for powerful use cases, but the Delegation Framework currently does not include any `Batch` compatible caveat enforcers.

delegation-toolkit/concepts/smart-accounts.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ See [Create a smart account](../guides/smart-accounts/create-smart-account.md) t
4343
### Hybrid smart account
4444

4545
The Hybrid smart account is a flexible implementation that supports both an externally owned account (EOA) owner and any number of passkey (WebAuthn) signers.
46-
You can configure any of these signers as the signatory, and use them to sign any data, including user operations, on behalf of the smart account.
46+
You can configure any of these signers, and use them to sign any data, including user operations, on behalf of the smart account.
4747

4848
This type is referenced in the toolkit as `Implementation.Hybrid`.
4949

@@ -79,7 +79,7 @@ The MetaMask Smart Accounts flow is as follows:
7979
tokens or third-party sponsorship.
8080

8181
2. **User operation creation** - For actions such as sending transactions, a user operation is created with
82-
necessary details and signed by the configured signatory.
82+
necessary details and signed by the configured signers.
8383

8484
3. **Bundlers and mempool** - The signed user operation is submitted to a special mempool, where bundlers
8585
collect and package multiple user operations into a single transaction to save on gas costs.

delegation-toolkit/experimental/erc-7710-redeem-delegations.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ This data encodes the authority that lets the delegate redeem the permission.
6565
### Security considerations for `accountMeta`
6666

6767
When a user grants a permission, they can provide `accountMeta` which is an array of `factory` and `factoryData` values.
68-
These calls must be executed before redeeming the permission (this is handled for you in [`sendUserOperationWithDelegation`](../reference/api/experimental-actions/bundler-client.md#senduseroperationwithdelegation)).
68+
These calls must be executed before redeeming the permission (this is handled for you in [`sendUserOperationWithDelegation`](../reference/erc7715/bundler-client.md#senduseroperationwithdelegation)).
6969

7070
Because each `accountMeta` is an arbitrary call specified by the granter, it is important that these are executed carefully.
7171
We recommend taking the following precautions:
@@ -86,7 +86,7 @@ Redeem a delegation with a [MetaMask smart account](#redeem-with-a-metamask-smar
8686
To redeem a delegation with a MetaMask smart account, [create a smart account](../guides/smart-accounts/create-smart-account.md)
8787
and a [Viem Bundler Client](https://viem.sh/account-abstraction/clients/bundler).
8888

89-
After setting up your Bundler Client, you can extend its functionality with `erc7710BundlerActions` actions to support ERC-7710. Once extended, use [`sendUserOperationWithDelegation`](../reference/api/experimental-actions/bundler-client.md#senduseroperationwithdelegation) to redeem the permission.
89+
After setting up your Bundler Client, you can extend its functionality with `erc7710BundlerActions` actions to support ERC-7710. Once extended, use [`sendUserOperationWithDelegation`](../reference/erc7715/bundler-client.md#senduseroperationwithdelegation) to redeem the permission.
9090

9191
<Tabs>
9292
<TabItem value="example.ts">
@@ -146,7 +146,7 @@ export const sessionAccount = await toMetaMaskSmartAccount({
146146
implementation: Implementation.Hybrid,
147147
deployParams: [account.address, [], [], []],
148148
deploySalt: "0x",
149-
signatory: { account },
149+
signer: { account },
150150
});
151151

152152
export const bundlerClient = createBundlerClient({
@@ -168,7 +168,7 @@ export const bundlerClient = createBundlerClient({
168168

169169
To redeem a delegation with an EOA, create a [Viem Wallet Client](https://viem.sh/docs/clients/wallet).
170170

171-
After creating your Wallet Client, you can extend its functionality with `erc7710WalletActions` actions to support ERC-7710. Once extended, use [`sendTransactionWithDelegation`](../reference/api/experimental-actions/wallet-client.md#sendtransactionwithdelegation) to redeem the permission.
171+
After creating your Wallet Client, you can extend its functionality with `erc7710WalletActions` actions to support ERC-7710. Once extended, use [`sendTransactionWithDelegation`](../reference/erc7715/wallet-client.md#sendtransactionwithdelegation) to redeem the permission.
172172

173173
<Tabs>
174174
<TabItem value="example.ts">

delegation-toolkit/experimental/erc-7715-request-permissions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const sessionAccount = await toMetaMaskSmartAccount({
8080
implementation: Implementation.Hybrid,
8181
deployParams: [account.address, [], [], []],
8282
deploySalt: "0x",
83-
signatory: { account },
83+
signer: { account },
8484
});
8585

8686
export const walletClient = createWalletClient({
@@ -165,7 +165,7 @@ You should always verify the granted permissions and adjust your dapp's behavior
165165
## Security considerations for `accountMeta`
166166

167167
When a user grants a permission, they can provide [`accountMeta`](erc-7710-redeem-delegations.md#extract-relevant-data) which is an array of `factory` and `factoryData` values.
168-
These calls must be executed before redeeming the permission (this is handled for you in [`sendUserOperationWithDelegation`](../reference/api/experimental-actions/bundler-client.md#senduseroperationwithdelegation)).
168+
These calls must be executed before redeeming the permission (this is handled for you in [`sendUserOperationWithDelegation`](../reference/erc7715/bundler-client.md#senduseroperationwithdelegation)).
169169

170170
Because each `accountMeta` is an arbitrary call specified by the granter, it is important that these are executed carefully.
171171
We recommend taking the following precautions:

delegation-toolkit/get-started/erc7715-quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const sessionAccount = await toMetaMaskSmartAccount({
8080
implementation: Implementation.Hybrid,
8181
deployParams: [account.address, [], [], []],
8282
deploySalt: "0x",
83-
signatory: { account },
83+
signer: { account },
8484
});
8585
```
8686

delegation-toolkit/get-started/smart-account-quickstart/eip7702.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ const smartAccount = await toMetaMaskSmartAccount({
135135
client: publicClient,
136136
implementation: Implementation.Stateless7702,
137137
address,
138-
signatory: { walletClient },
138+
signer: { walletClient },
139139
});
140140
```
141141

delegation-toolkit/get-started/smart-account-quickstart/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const smartAccount = await toMetaMaskSmartAccount({
6868
implementation: Implementation.Hybrid,
6969
deployParams: [account.address, [], [], []],
7070
deploySalt: "0x",
71-
signatory: { account },
71+
signer: { account },
7272
});
7373
```
7474

delegation-toolkit/guides/configure-toolkit.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const delegatorSmartAccount = await toMetaMaskSmartAccount({
103103
implementation: Implementation.Hybrid,
104104
deployParams: [delegatorAccount.address, [], [], []],
105105
deploySalt: "0x",
106-
signatory: { account: delegatorAccount },
106+
signer: { account: delegatorAccount },
107107
});
108108

109109
export delegatorSmartAccount;
@@ -116,7 +116,7 @@ export delegatorSmartAccount;
116116
See the changelog of the toolkit version you are using (in the left sidebar) for supported chains.
117117
:::
118118

119-
Alternatively, you can use the [`getDelegatorEnvironment`](../reference/api/delegation.md#getdelegatorenvironment) function to resolve the environment.
119+
Alternatively, you can use the [`getDelegatorEnvironment`](../reference/delegation/index.md#getdelegatorenvironment) function to resolve the environment.
120120
This function is especially useful if your delegator is not a smart account when
121121
creating a [redelegation](../concepts/delegation/index.md#delegation-types).
122122

@@ -132,7 +132,7 @@ const environment: DeleGatorEnvironment = getDelegatorEnvironment(11155111);
132132

133133
### Deploy a custom environment
134134

135-
You can deploy the contracts using any method, but the toolkit provides a convenient [`deployDelegatorEnvironment`](../reference/api/delegation.md#deploydelegatorenvironment) function. This function simplifies deploying the Delegation Framework contracts to your desired EVM chain.
135+
You can deploy the contracts using any method, but the toolkit provides a convenient [`deployDelegatorEnvironment`](../reference/delegation/index.md#deploydelegatorenvironment) function. This function simplifies deploying the Delegation Framework contracts to your desired EVM chain.
136136

137137
This function requires a Viem [Public Client](https://viem.sh/docs/clients/public.html), [Wallet Client](https://viem.sh/docs/clients/wallet.html), and [Chain](https://viem.sh/docs/glossary/types#chain)
138138
to deploy the contracts and resolve the `DeleGatorEnvironment`.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
description: Learn how to check the delegation state.
3+
sidebar_label: Check the delegation state
4+
toc_max_heading_level: 3
5+
---
6+
7+
import Tabs from "@theme/Tabs";
8+
import TabItem from "@theme/TabItem";
9+
10+
# Check the delegation state
11+
12+
When using [spending limit delegation scopes](use-delegation-scopes/spending-limit.md) or relevant [caveat enforcers](../../reference/delegation/caveats.md),
13+
you might need to check the remaining transferrable amount in a delegation.
14+
For example, if a delegation allows a user to spend 10 USDC per week and they have already spent 10 - n USDC in the current period,
15+
you can determine how much of the allowance is still available for transfer.
16+
17+
Use the `CaveatEnforcerClient` to check the available balances for specific scopes or caveats.
18+
19+
## Prerequisites
20+
21+
- [Install and set up the Delegation Toolkit.](../../get-started/install.md)
22+
- [Create a delegator account.](execute-on-smart-accounts-behalf.md#3-create-a-delegator-account)
23+
- [Create a delegate account.](execute-on-smart-accounts-behalf.md#4-create-a-delegate-account)
24+
- [Create a delegation with an ERC-20 periodic scope.](use-delegation-scopes/spending-limit.md#erc-20-periodic-scope)
25+
26+
## Create a `CaveatEnforcerClient`
27+
28+
To check the delegation state, create a [`CaveatEnforcerClient`](../../reference/delegation/caveat-enforcer-client.md).
29+
This client allows you to interact with the caveat enforcers of the delegation, and read the required state.
30+
31+
<Tabs>
32+
<TabItem value="example.ts">
33+
34+
```typescript
35+
import { environment, publicClient as client } from './config.ts'
36+
import { createCaveatEnforcerClient } from '@metamask/delegation-toolkit'
37+
38+
const caveatEnforcerClient = createCaveatEnforcerClient({
39+
environment,
40+
client,
41+
})
42+
```
43+
44+
</TabItem>
45+
<TabItem value="config.ts">
46+
47+
```typescript
48+
import { sepolia as chain } from 'viem/chains'
49+
import { createPublicClient, http } from 'viem'
50+
import { getDeleGatorEnvironment } from '@metamask/delegation-toolkit'
51+
52+
export const environment = getDeleGatorEnvironment(chain.id)
53+
54+
export const publicClient = createPublicClient({
55+
chain,
56+
transport: http(),
57+
})
58+
```
59+
60+
</TabItem>
61+
</Tabs>
62+
63+
## Read the caveat enforcer state
64+
65+
This example uses the [`getErc20PeriodTransferEnforcerAvailableAmount`](../../reference/delegation/caveat-enforcer-client.md#geterc20periodtransferenforceravailableamount) method to read the state and retrieve the remaining amount for the current transfer period.
66+
67+
<Tabs>
68+
<TabItem value="example.ts">
69+
70+
```typescript
71+
import { delegation } './config.ts'
72+
73+
// Returns the available amount for current period.
74+
const { availableAmount } = await caveatEnforcerClient.getErc20PeriodTransferEnforcerAvailableAmount({
75+
delegation,
76+
})
77+
```
78+
79+
</TabItem>
80+
<TabItem value="config.ts">
81+
82+
```typescript
83+
import { createDelegation } from '@metamask/delegation-toolkit'
84+
85+
export const delegation = createDelegation({
86+
scope: {
87+
type: 'erc20PeriodTransfer',
88+
tokenAddress: '0xb4aE654Aca577781Ca1c5DE8FbE60c2F423f37da',
89+
periodAmount: 1000000000000000000n,
90+
periodDuration: 86400,
91+
startDate: 1743763600,
92+
},
93+
to: delegateAccount,
94+
from: delegatorAccount,
95+
environment: delegatorAccount.environment,
96+
})
97+
```
98+
99+
</TabItem>
100+
</Tabs>
101+
102+
## Next steps
103+
104+
See the [Caveat Enforcer Client reference](../../reference/delegation/caveat-enforcer-client.md) for the full list of available methods.

0 commit comments

Comments
 (0)