Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ const sessionAccount = privateKeyToAccount("0x...");
### 4. Request ERC-7715 permissions

Request ERC-7715 permissions from the user. In this example, you'll request an ERC-20 periodic
permission using the `grantPermissions` method.
permission using the Wallet Client's [`requestExecutionPermissions`](../../reference/erc7715/wallet-client.md#requestexecutionpermissions) action.

```typescript
import { sepolia as chain } from "viem/chains";
import { parseUnits } from "viem";

// Since current time is in seconds, we need to convert milliseconds to seconds.
const currentTime = Math.floor(Date.now() / 1000);
Expand All @@ -125,12 +126,13 @@ const grantedPermissions = await walletClient.requestExecutionPermissions([{
data: {
tokenAddress,
// 1 USDC in WEI format. Since USDC has 6 decimals, 10 * 10^6
periodAmount: 1000000n,
periodAmount: parseUnits("10", 6),
// 1 day in seconds
periodDuration: 86400,
justification?: "Permission to transfer 1 USDC every day",
},
},
isAdjustmentAllowed: true,
}]);
```

Expand Down Expand Up @@ -183,9 +185,11 @@ const sessionAccountWalletClient = createWalletClient({

### 6. Redeem ERC-7715 permissions

The session account can now [redeem the delegation](../experimental/erc-7710-redeem-delegations.md). The redeem transaction is sent to the `DelegationManager` contract, which validates the delegation and executes actions on the user's behalf.
The session account can now redeem the permissions. The redeem transaction is sent to the `DelegationManager` contract, which validates the delegation and executes actions on the user's behalf.

To redeem the permissions, use the appropriate client action based on your session account type:
To redeem the permissions, use the client action based on your session account type.
A smart account uses the Bundler Client's [`sendUserOperationWithDelegation`](../../reference/erc7715/bundler-client.md#senduseroperationwithdelegation) action,
and an EOA uses the Wallet Client's [`sendTransactionWithDelegation`](../../reference/erc7715/wallet-client.md#sendtransactionwithdelegation) action:

<Tabs>
<TabItem value="Smart account">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ permissions for ERC-20 token transfers with time-based (periodic) or streaming c

- [Install and set up the Delegation Toolkit.](../../../get-started/install.md)
- [Configure the Delegation Toolkit.](../../configure-toolkit.md)
- [Create a session account.](../execute-on-metamask-user-behalf.md#3-set-up-a-session-account)
- [Create a session account.](../execute-on-metamask-users-behalf.md#3-set-up-a-session-account)

## ERC-20 periodic permission

Expand Down Expand Up @@ -124,8 +124,6 @@ const grantedPermissions = await walletClient.requestExecutionPermissions([{
initialAmount: parseUnits("1", 6),
// 2 USDC in WEI format. Since USDC has 6 decimals, 2 * 10^6.
maxAmount: parseUnits("2", 6),
// 1 hour in seconds.
duration: 3600,
startTime: currentTime,
justification: "Permission to use 0.1 USDC per second",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ permissions for native token transfers with time-based (periodic) or streaming c

- [Install and set up the Delegation Toolkit.](../../../get-started/install.md)
- [Configure the Delegation Toolkit.](../../configure-toolkit.md)
- [Create a session account.](../execute-on-metamask-user-behalf.md#3-set-up-a-session-account)
- [Create a session account.](../execute-on-metamask-users-behalf.md#3-set-up-a-session-account)

## Native token periodic permission

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ keywords: [delegation state, caveat enforcer client, API, methods, reference]
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

# Caveat Enforcer Client
# Caveat Enforcer Client reference

The following API methods are related to `CaveatEnforcerClient` used to [check the delegation state](../../guides/delegation/check-delegation-state.md).

Expand Down
3 changes: 2 additions & 1 deletion delegation-toolkit/reference/delegation/caveats.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
description: Caveat enforcers reference.
sidebar_label: Caveats
toc_max_heading_level: 2
keywords: [caveats, caveat enforcers, configuration, smart contracts, reference]
---

# Caveats
# Caveats reference

When [constraining a delegation scope](../../guides/delegation/use-delegation-scopes/constrain-scope.md), you can specify the following caveat types.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
description: Delegation scopes reference.
sidebar_label: Delegation scopes
keywords: [delegation scopes, configuration, reference]
---

Expand Down
19 changes: 10 additions & 9 deletions delegation-toolkit/reference/erc7715/bundler-client.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
---
description: Bundler Client API methods reference.
sidebar_label: Bundler Client
description: Bundler Client actions reference.
sidebar_label: Bundler Client actions
toc_max_heading_level: 2
keywords: [ERC-7715, Viem, bundler client, actions, reference]
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

# Bundler Client API reference
# Bundler Client actions reference

The following API methods are related to the [Viem Bundler Client](https://viem.sh/account-abstraction/clients/bundler).
The following actions are related to the [Viem Bundler Client](https://viem.sh/account-abstraction/clients/bundler) used to [execute on a MetaMask user's behalf](../../guides/erc7715/execute-on-metamask-users-behalf.md).

## `sendUserOperationWithDelegation`

Sends a user operation to redeem delegated permissions according to the [ERC-7710](https://eips.ethereum.org/EIPS/eip-7710) specifications.
Sends a user operation with redeem permissions according to the [ERC-7710](https://eips.ethereum.org/EIPS/eip-7710) specifications.

:::info
To use `sendUserOperationWithDelegation`, the Viem Bundler Client must be
Expand All @@ -29,16 +30,16 @@ Objects in the `calls` array also require the following parameters:

| Name | Type | Required | Description |
| ---- | ---- | -------- |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `delegationManager` | `0x${string}` | Yes | The address of Delegation Manager. |
| `permissionsContext` | `0x${string}` | Yes | Encoded calldata for redeeming delegations. If you're not using ERC-7715, you can use the [`redeemDelegations`](../delegation/index.md#redeemdelegations) utility function to generate the calldata manually. |
| `delegationManager` | `Address` | Yes | The address of Delegation Manager. |
| `permissionsContext` | `Hex` | Yes | Encoded calldata for redeeming permissions. If you're not using ERC-7715, you can use the [`redeemDelegations`](../delegation/index.md#redeemdelegations) utility function to generate the calldata manually. |

### Example

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

```ts
import { sessionAccount, bundlerClient, publicClient } from "./config.ts";
import { sessionAccount, bundlerClient, publicClient } from "./client.ts";

// These properties must be extracted from the permission response.
const permissionsContext = permissionsResponse[0].context;
Expand Down Expand Up @@ -67,7 +68,7 @@ const userOperationHash = await bundlerClient.sendUserOperationWithDelegation({
```

</TabItem>
<TabItem value ="config.ts">
<TabItem value ="client.ts">

```ts
import { createPublicClient, http, createBundlerClient } from "viem";
Expand Down
2 changes: 1 addition & 1 deletion delegation-toolkit/reference/erc7715/permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_label: Permissions
keywords: [ERC-7715, permissions, ERC-20 token, native token, reference]
---

# ERC-7715 permissions
# ERC-7715 permissions reference

When [executing on a MetaMask user's behalf](../../guides/erc7715/execute-on-metamask-users-behalf.md), you can request the following permission types for ERC-20 token and native token transfers.
Learn [how to use ERC-7715 permissions](../../guides/erc7715/use-permissions/erc20-token.md).
Expand Down
56 changes: 27 additions & 29 deletions delegation-toolkit/reference/erc7715/wallet-client.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
---
description: Wallet Client API methods reference.
sidebar_label: Wallet Client
description: Wallet Client actions reference.
sidebar_label: Wallet Client actions
toc_max_heading_level: 2
keywords: [ERC-7715, Viem, wallet client, actions, reference]
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

# Wallet Client API reference
# Wallet Client actions reference

The following API methods are related to the [Viem Wallet Client](https://viem.sh/docs/clients/wallet).
The following actions are related to the [Viem Wallet Client](https://viem.sh/docs/clients/wallet) used to [execute on a MetaMask user's behalf](../../guides/erc7715/execute-on-metamask-users-behalf.md).

## `grantPermissions`
## `requestExecutionPermissions`

Requests permissions from the MetaMask extension account according to the [ERC-7715](https://eips.ethereum.org/EIPS/eip-7715) specifications.

:::info
To use `grantPermissions`, the Viem Wallet Client must be extended with `erc7715ProviderActions`.
To use `requestExecutionPermissions`, the Viem Wallet Client must be extended with `erc7715ProviderActions`.
:::

### Parameters
Expand All @@ -26,9 +27,9 @@ To use `grantPermissions`, the Viem Wallet Client must be extended with `erc7715
| `chainId` | `number` | Yes | The chain ID on which the permission is being requested. |
| `address` | `Address` | No | Address of the wallet to which the permission is being requested. |
| `expiry` | `number` | Yes | The timestamp (in seconds) by which the permission must expire. |
| `permission` | `Permission` | Yes | The permission to grant to the user. |
| `signer` | `Signer` | Yes | The account to which the permission will be assigned. |
| `isAdjustmentAllowed` | `boolean` | No | Whether the user is allowed to modify the requested permission. The default is `true`. |
| `permission` | `SupportedPermissionParams` | Yes | The permission to be requested. The toolkit supports multiple [ERC-7715 permissions](permissions.md). |
| `signer` | `SignerParam` | Yes | The account to which the permission will be assigned. |
| `isAdjustmentAllowed` | `boolean` | Yes | Defines whether the user is allowed to modify the requested permission. |

### Example

Expand All @@ -37,39 +38,36 @@ To use `grantPermissions`, the Viem Wallet Client must be extended with `erc7715

```ts
import { sepolia as chain } from "viem/chains";
import { walletClient } from "./config.ts";
import { parseUnits } from "viem";
import { walletClient } from "./client.ts";

const expiry = Math.floor(Date.now() / 1000 + 604_800); // 1 week from now.
const currentTime = Math.floor(Date.now() / 1000); // now
const currentTime = Math.floor(Date.now() / 1000);
const expiry = currentTime + 604800;

// Address of the wallet that will manage the session. It can
// be either a smart account or an externally owned account (EOA)
const sessionAccount = "0x1431..";

const grantedPermissions = await walletClient.grantPermissions([{
const grantedPermissions = await walletClient.requestExecutionPermissions([{
chainId: chain.id,
expiry,
signer: {
type: "account",
data: {
address: sessionAccount,
address: "0x0955fFD7b83e5493a8c1FD5dC87e2CF37Eacc44a",
},
},
permission: {
type: "native-token-stream",
type: "erc20-token-periodic",
data: {
initialAmount: 1n, // 1 wei
amountPerSecond: 1n, // 1 wei per second
maxAmount: 10n, // 10 wei
startTime: currentTime,
justification: "Payment for a week long subscription",
tokenAddress: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
periodAmount: parseUnits("10", 6),
periodDuration: 86400,
justification?: "Permission to transfer 1 USDC every day",
},
},
isAdjustmentAllowed: true,
}]);
```

</TabItem>
<TabItem value ="config.ts">
<TabItem value ="client.ts">

```ts
import { createWalletClient, custom } from "viem";
Expand Down Expand Up @@ -99,16 +97,16 @@ This function has the same parameters, and it also requires the following parame

| Name | Type | Required | Description |
| ---- | ---- | -------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `delegationManager` | `0x${string}` | Yes | The address of the Delegation Manager. |
| `permissionsContext` | `0x${string}` | Yes | Encoded calldata for redeeming delegations. If you're not using ERC-7715, you can use the [`redeemDelegations`](../delegation/index.md#redeemdelegations) utility function to generate the calldata manually. |
| `delegationManager` | `Address` | Yes | The address of the Delegation Manager. |
| `permissionsContext` | `Hex` | Yes | Encoded calldata for redeeming delegations. If you're not using ERC-7715, you can use the [`redeemDelegations`](../delegation/index.md#redeemdelegations) utility function to generate the calldata manually. |

### Example

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

```ts
import { walletClient, publicClient } from "./config.ts";
import { walletClient, publicClient } from "./client.ts";

// These properties must be extracted from the permission response. See
// `grantPermissions` action to learn how to request permissions.
Expand Down Expand Up @@ -141,7 +139,7 @@ const hash = walletClient.sendTransactionWithDelegation({
```

</TabItem>
<TabItem value ="config.ts">
<TabItem value ="client.ts">

```ts
import { http, createPublicClient, createWalletClient } from "viem";
Expand Down
4 changes: 2 additions & 2 deletions gator-sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ const sidebar = {
collapsed: true,
items: [
'reference/erc7715/permissions',
// 'reference/erc7715/wallet-client',
// 'reference/erc7715/bundler-client',
'reference/erc7715/wallet-client',
'reference/erc7715/bundler-client',
],
},
],
Expand Down
Loading