Skip to content

Commit 44f4b1b

Browse files
AyushBherwani1998alexandratranjeffsmale90
authored
Update delegation-toolkit docs for v0.12 release
* update docs for v0.12 * update quick start * fix typos * fix typo * fix typo * add 7702 content * fix typos * rename file * Apply suggestions from code review Co-authored-by: Alexandra Carrillo <[email protected]> * update code snippets to use sepolia * Apply suggestions from code review Co-authored-by: jeffsmale90 <[email protected]> * Minor nit Co-authored-by: jeffsmale90 <[email protected]> * update prerequisites --------- Co-authored-by: Alexandra Carrillo <[email protected]> Co-authored-by: jeffsmale90 <[email protected]>
1 parent a256a5b commit 44f4b1b

16 files changed

+514
-110
lines changed

delegation-toolkit/concepts/environment.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {
4242
} from "@metamask/delegation-toolkit";
4343
import { privateKeyToAccount } from "viem/accounts";
4444
import { createPublicClient, http } from "viem";
45-
import { lineaSepolia as chain } from "viem/chains";
45+
import { sepolia as chain } from "viem/chains";
4646

4747
const publicClient = createPublicClient({
4848
chain,
@@ -79,8 +79,8 @@ import {
7979
DeleGatorEnvironment,
8080
} from "@metamask/delegation-toolkit";
8181

82-
// Resolves the DeleGatorEnvironment for Linea Sepolia
83-
const environment: DeleGatorEnvironment = getDelegatorEnvironment(59141);
82+
// Resolves the DeleGatorEnvironment for Sepolia
83+
const environment: DeleGatorEnvironment = getDelegatorEnvironment(11155111);
8484
```
8585

8686
## Deploy custom delegator environment
@@ -97,7 +97,8 @@ Your wallet must have sufficient native token balance to deploy the contracts.
9797

9898
```typescript
9999
import { walletClient, publicClient } from "./config.ts";
100-
import { lineaSepolia as chain } from "viem/chains";
100+
import { sepolia as chain } from "viem/chains";
101+
import { deployDeleGatorEnvironment } from "@metamask/delegation-toolkit/utils";
101102

102103
const environment = await deployDeleGatorEnvironment(
103104
walletClient,
@@ -111,7 +112,7 @@ const environment = await deployDeleGatorEnvironment(
111112

112113
```typescript
113114
import { privateKeyToAccount } from "viem/accounts";
114-
import { lineaSepolia as chain } from "viem/chains";
115+
import { sepolia as chain } from "viem/chains";
115116
import { http, createWalletClient, createPublicClient } from "viem";
116117

117118
// Your deployer wallet private key.
@@ -139,7 +140,8 @@ For example, if you've already deployed the `EntryPoint` contract on the target
139140
```typescript
140141
// The config.ts is the same as in the previous example.
141142
import { walletClient, publicClient } from "./config.ts";
142-
import { lineaSepolia as chain } from "viem/chains";
143+
import { sepolia as chain } from "viem/chains";
144+
import { deployDeleGatorEnvironment } from "@metamask/delegation-toolkit/utils";
143145

144146
const environment = await deployDeleGatorEnvironment(
145147
walletClient,
@@ -163,12 +165,12 @@ To override the delegator environment, the toolkit provides an [`overrideDeploye
163165
```typescript
164166
// The config.ts is the same as in the previous example.
165167
import { walletClient, publicClient } from "./config.ts";
166-
import { lineaSepolia as chain } from "viem/chains";
168+
import { sepolia as chain } from "viem/chains";
169+
import { DeleGatorEnvironment } from "@metamask/delegation-toolkit";
167170
import {
168-
DeleGatorEnvironment,
169171
overrideDeployedEnvironment,
170-
deployDeleGatorEnvironment
171-
} from "@metamask/delegation-toolkit";
172+
deployDeleGatorEnvironment
173+
} from "@metamask/delegation-toolkit/utils";
172174

173175
const environment: DeleGatorEnvironment = await deployDeleGatorEnvironment(
174176
walletClient,
@@ -188,14 +190,14 @@ If you've already deployed the contracts using a different method, you can creat
188190
```typescript
189191
// remove-start
190192
- import { walletClient, publicClient } from "./config.ts";
191-
- import { lineaSepolia as chain } from "viem/chains";
193+
- import { sepolia as chain } from "viem/chains";
192194
// remove-end
195+
import { DeleGatorEnvironment } from "@metamask/delegation-toolkit";
193196
import {
194-
DeleGatorEnvironment,
195197
overrideDeployedEnvironment,
196198
// remove-next-line
197199
- deployDeleGatorEnvironment
198-
} from "@metamask/delegation-toolkit";
200+
} from "@metamask/delegation-toolkit/utils";
199201

200202
// remove-start
201203
- const environment: DeleGatorEnvironment = await deployDeleGatorEnvironment(

delegation-toolkit/concepts/smart-accounts.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ ERC-4337 introduces the following concepts:
3838

3939
## Smart account implementation types
4040

41-
The MetaMask Delegation Toolkit supports two types of smart accounts, each offering unique features and use cases.
41+
The MetaMask Delegation Toolkit supports three types of smart accounts, each offering unique features and use cases.
42+
4243
See [Configure accounts and signers](../how-to/create-smart-account/configure-accounts-signers.md) to learn how to use these different account types.
4344

4445
### Hybrid smart account
@@ -55,6 +56,13 @@ The signatory must have at least as many signers include as the threshold is con
5556

5657
This type is referenced in the toolkit as `Implementation.Multisig`.
5758

59+
### Stateless 7702 smart account
60+
61+
The Stateless 7702 smart account implementation represents an externally owned account (EOA) upgraded to
62+
support smart account functionality as defined by [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702). This implementation enables EOAs to perform smart account operations, including the creation and management of delegations.
63+
64+
This type is referenced in the toolkit as `Implementation.Stateless7702`.
65+
5866
## Smart account flow
5967

6068
The MetaMask smart account flow is as follows:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
description: Get started with the MetaMask Delegation Toolkit using the `create-gator-app` CLI.
3-
sidebar_position: 3
3+
sidebar_position: 4
44
sidebar_label: CLI quickstart
55
---
66

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
---
2+
description: Upgrade an externally owned account (EOA) to a smart account
3+
sidebar_position: 3
4+
sidebar_label: EIP-7702 quickstart
5+
---
6+
7+
# EIP-7702 quickstart
8+
9+
This page demonstrates how to upgrade your externally owned account (EOA) to support MetaMask smart account
10+
functionality using an [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) transaction. This enables your EOA to leverage the benefits of account
11+
abstraction, such as batch transactions, gas sponsorship, and [ERC-7710 delegation capabilities](./../concepts/delegation.md).
12+
13+
## Prerequisites
14+
15+
- [Install and set up the Delegation Toolkit.](install.md)
16+
- [Install Viem](https://viem.sh/)
17+
18+
## Steps
19+
20+
### 1. Set up a Public Client
21+
22+
Set up a [Viem Public Client](https://viem.sh/docs/clients/public) using Viem's `createPublicClient` function.
23+
This client will let the EOA query the account state and interact with blockchain network.
24+
25+
```typescript
26+
import { createPublicClient, http } from "viem";
27+
import { sepolia as chain } from "viem/chains";
28+
29+
const publicClient = createPublicClient({
30+
chain,
31+
transport: http(),
32+
});
33+
```
34+
35+
### 2. Set up a Bundler Client
36+
37+
Set up a [Viem Bundler Client](https://viem.sh/account-abstraction/clients/bundler) using Viem's `createBundlerClient` function.
38+
This lets you use the bundler service to estimate gas for user operations and submit transactions to the network.
39+
40+
```typescript
41+
import { createBundlerClient } from "viem/account-abstraction";
42+
43+
const bundlerClient = createBundlerClient({
44+
client: publicClient,
45+
transport: http("https://your-bundler-rpc.com"),
46+
});
47+
```
48+
49+
### 3. Set up a Wallet Client
50+
51+
Set up [Viem Wallet Client](https://viem.sh/docs/clients/wallet) using Viem's `createWalletClient` function.
52+
This lets you sign and submit EIP-7702 authorization.
53+
54+
```typescript
55+
import { createWalletClient, http } from "viem";
56+
import { sepolia as chain } from "viem/chains";
57+
import { privateKeyToAccount } from "viem/accounts";
58+
59+
export const account = privateKeyToAccount("0x...");
60+
61+
export const walletClient = createWalletClient({
62+
account,
63+
chain,
64+
transport: http(),
65+
});
66+
```
67+
68+
### 4. Authorize a 7702 delegation
69+
70+
Create an authorization to map the contract code to an EOA, and sign it
71+
using Viem's [`signAuthorization`](https://viem.sh/docs/eip7702/signAuthorization) action. The `signAuthorization` action
72+
does not support JSON-RPC accounts.
73+
74+
This example uses [`EIP7702StatelessDeleGator`](https://github.com/MetaMask/delegation-framework/blob/main/src/EIP7702/EIP7702StatelessDeleGator.sol) as the EIP-7702 delegator contract.
75+
It follows a stateless design, as it does not store signer data in the contract's state. This approach
76+
provides a lightweight and secure way to upgrade an EOA to a smart account.
77+
78+
```typescript
79+
import {
80+
Implementation,
81+
toMetaMaskSmartAccount,
82+
getDeleGatorEnvironment,
83+
} from "@metamask/delegation-toolkit";
84+
import { privateKeyToAccount } from "viem/accounts";
85+
86+
const environment = getDeleGatorEnvironment(sepolia.id);
87+
const contractAddress = environment.implementations.EIP7702StatelessDeleGatorImpl;
88+
89+
const authorization = await walletClient.signAuthorization({
90+
account,
91+
contractAddress,
92+
executor: "self",
93+
});
94+
```
95+
96+
### 5. Submit the authorization
97+
98+
Once you have signed an authorization, you can send an EIP-7702 transaction to set the EOA code.
99+
Since the authorization cannot be sent by itself, you can include it alongside a dummy transaction.
100+
101+
```ts
102+
import { zeroAddress } from "viem";
103+
104+
const hash = await walletClient.sendTransaction({
105+
authorizationList: [authorization],
106+
data: "0x",
107+
to: zeroAddress,
108+
});
109+
```
110+
111+
### 6. Create a MetaMask smart account
112+
113+
Create a smart account instance for the EOA and start
114+
leveraging the benefits of account abstraction.
115+
116+
```ts
117+
import {
118+
Implementation,
119+
toMetaMaskSmartAccount,
120+
} from "@metamask/delegation-toolkit";
121+
122+
const addresses = await walletClient.getAddresses();
123+
const address = addresses[0];
124+
125+
const smartAccount = await toMetaMaskSmartAccount({
126+
client: publicClient,
127+
implementation: Implementation.Stateless7702,
128+
address,
129+
signatory: { walletClient },
130+
});
131+
```
132+
133+
### 7. Send a user operation
134+
135+
Send a user operation through the upgraded EOA, using Viem's [`sendUserOperation`](https://viem.sh/account-abstraction/actions/bundler/sendUserOperation) method.
136+
137+
```ts
138+
import { parseEther } from "viem";
139+
140+
// Appropriate fee per gas must be determined for the specific bundler being used.
141+
const maxFeePerGas = 1n;
142+
const maxPriorityFeePerGas = 1n;
143+
144+
const userOperationHash = await bundlerClient.sendUserOperation({
145+
account: smartAccount,
146+
calls: [
147+
{
148+
to: "0x1234567890123456789012345678901234567890",
149+
value: parseEther("1")
150+
}
151+
],
152+
maxFeePerGas,
153+
maxPriorityFeePerGas
154+
});
155+
```

delegation-toolkit/get-started/quickstart.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This client will let the delegator account query the signer's account state and
2222

2323
```typescript
2424
import { createPublicClient, http } from "viem";
25-
import { lineaSepolia as chain } from "viem/chains";
25+
import { sepolia as chain } from "viem/chains";
2626

2727
const publicClient = createPublicClient({
2828
chain,
@@ -101,6 +101,13 @@ delegator account to the delegate account.
101101
This example passes an empty `caveats` array, which means the delegate can perform any action on the delegator's behalf.
102102
We recommend [restricting the delegation](../how-to/create-delegation/restrict-delegation.md) by adding caveat enforcers.
103103

104+
:::warning Important
105+
106+
Before creating a delegation, ensure that the delegator account has
107+
been deployed. If the account is not deployed, redeeming the delegation will fail.
108+
109+
:::
110+
104111
```typescript
105112
import { createDelegation } from "@metamask/delegation-toolkit";
106113

@@ -137,18 +144,16 @@ executes actions on the delegator's behalf.
137144
To prepare the calldata for the redeem transaction, use the [`redeemDelegation`](../reference/api/delegation.md#redeemdelegation) utility function from the Delegation Toolkit.
138145

139146
```typescript
140-
import {
141-
createExecution,
142-
DelegationFramework,
143-
SINGLE_DEFAULT_MODE,
144-
} from "@metamask/delegation-toolkit";
147+
import { createExecution } from "@metamask/delegation-toolkit";
148+
import { DelegationManager } from "@metamask/delegation-toolkit/contracts";
149+
import { SINGLE_DEFAULT_MODE } from "@metamask/delegation-toolkit/utils";
145150
import { zeroAddress } from "viem";
146151

147152
const delegations = [ signedDelegation ];
148153

149-
const executions = createExecution(zeroAddress);
154+
const executions = createExecution({ target: zeroAddress });
150155

151-
const redeemDelegationCalldata = DelegationFramework.encode.redeemDelegations({
156+
const redeemDelegationCalldata = DelegationManager.encode.redeemDelegations({
152157
delegations: [ delegations ],
153158
modes: [ SINGLE_DEFAULT_MODE ],
154159
executions: [ executions ]

delegation-toolkit/get-started/supported-networks.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,31 @@ If you don't see the network you're looking for, you can request support by emai
1111

1212
## Mainnet networks
1313

14-
| Network Name | v0.10.1 | v0.10.2 | v0.11.0 |
14+
| Network Name | v0.10.2 | v0.11.0 | v0.12.0 |
1515
| ------------------- | ------- | ------- | ------- |
1616
| Ethereum ||||
1717
| Polygon ||||
1818
| Binance Smart Chain ||||
1919
| Optimism ||||
20-
| Arbitrum ||||
20+
| Arbitrum One ||||
2121
| Base ||||
2222
| Gnosis Chain ||||
23+
| Unichain ||||
24+
| Arbitrum Nova ||||
25+
| Berachain ||||
2326

2427
## Testnet networks
2528

26-
| Network Name | v0.10.1 | v0.10.2 | v0.11.0 |
27-
| ---------------- | ------- | ------- | ------- |
28-
| Ethereum Sepolia ||||
29-
| Base Sepolia ||||
30-
| MegaEth ||||
31-
| Gnosis Chiado ||||
29+
| Network Name | v0.10.2 | v0.11.0 | v0.12.0 |
30+
| --------------------------- | ------- | ------- | ------- |
31+
| Ethereum Sepolia ||||
32+
| Base Sepolia ||||
33+
| MegaEth ||||
34+
| Gnosis Chiado ||||
35+
| Arbitrum Sepolia ||||
36+
| Unichain Sepolia ||||
37+
| Berachain Bepolia ||||
38+
| Optimism Sepolia ||||
39+
| Binance Smart Chain ||||
40+
| Polygon Amoy ||||
41+
| Monad ||||

delegation-toolkit/how-to/configure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
createBundlerClient,
3838
} from "viem/account-abstraction";
3939
import { http } from "viem";
40-
import { lineaSepolia as chain } from "viem/chains";
40+
import { sepolia as chain } from "viem/chains";
4141

4242
// Replace these URLs with your actual bundler and paymaster endpoints.
4343
const bundlerUrl = "https://your-bundler-url.com";

delegation-toolkit/how-to/create-delegation/create-custom-caveat-enforcer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const delegation = createDelegation({
122122

123123
```typescript
124124
import { createPublicClient, http } from "viem";
125-
import { lineaSepolia as chain } from "viem/chains";
125+
import { sepolia as chain } from "viem/chains";
126126
import {
127127
Implementation,
128128
toMetaMaskSmartAccount,

0 commit comments

Comments
 (0)