Skip to content

Commit dab8eba

Browse files
committed
Merge branch 'main' into 2240-delegator-environment
# Conflicts: # src/pages/tutorials/create-custom-caveat-enforcer.md # src/pages/tutorials/use-erc20-paymaster.md # src/pages/tutorials/use-passkey-as-backup-signer.md
2 parents c238c92 + 735cb0a commit dab8eba

File tree

3 files changed

+72
-28
lines changed

3 files changed

+72
-28
lines changed

src/pages/tutorials/create-custom-caveat-enforcer.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ In this tutorial, you'll create and apply a caveat enforcer that only allows a d
1818

1919
## Prerequisites
2020

21-
- [Install and set up the Delegation Toolkit](/delegation-toolkit/get-started/install) in your project.
22-
- [Install Foundry and Forge.](https://getfoundry.sh/introduction/installation)
21+
- Install [Node.js](https://nodejs.org/en/blog/release/v18.18.0) v18 or later.
22+
- Install [Yarn](https://yarnpkg.com/),
23+
[npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), or another package manager.
24+
- [Install Foundry and Forge](https://getfoundry.sh/introduction/installation).
2325
- Get an [Infura API key](/developer-tools/dashboard/get-started/create-api) from the MetaMask Developer dashboard.
2426
- Have a MetaMask account with some Sepolia ETH to deploy your contract.
2527
:::note
@@ -28,7 +30,15 @@ In this tutorial, you'll create and apply a caveat enforcer that only allows a d
2830

2931
## Steps
3032

31-
### 1. Create the caveat enforcer
33+
### 1. Install the toolkit
34+
35+
Install the [MetaMask Delegation Toolkit](https://www.npmjs.com/package/@metamask/delegation-toolkit) in your project:
36+
37+
```bash npm2yarn
38+
npm install @metamask/delegation-toolkit
39+
```
40+
41+
### 2. Create the caveat enforcer
3242

3343
At the root of your project, create a `contracts` directory.
3444
In that directory, create a new contract named `AfterTimestampEnforcer.sol`.
@@ -74,7 +84,7 @@ contract AfterTimestampEnforcer is CaveatEnforcer {
7484
}
7585
```
7686

77-
### 2. Deploy the caveat enforcer
87+
### 3. Deploy the caveat enforcer
7888

7989
Deploy your custom caveat enforcer using [Forge](https://book.getfoundry.sh/forge/deploying) to obtain its contract address.
8090
Replace `<YOUR-API-KEY>` with your Infura API key, and `<YOUR-PRIVATE-KEY>` with the private key of your MetaMask account:
@@ -88,7 +98,7 @@ forge create src/AfterTimestampEnforcer.sol:AfterTimestampEnforcer \
8898

8999
The Forge CLI will display the address of the deployed caveat enforcer.
90100

91-
### 3. Apply the caveat enforcer
101+
### 4. Apply the caveat enforcer
92102

93103
Specify the address of the deployed `AfterTimestampEnforcer.sol` contract, add it to the caveat builder, and create a delegation.
94104
Learn more about [applying caveats to a delegation](/delegation-toolkit/development/guides/delegation/restrict-delegation).

src/pages/tutorials/use-erc20-paymaster.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,22 @@ This removes the need for users to hold native tokens, allowing them to perform
1919

2020
## Prerequisites
2121

22-
- [Install and set up the Delegation Toolkit](/delegation-toolkit/get-started/install) in your project.
23-
- [Create a Hybrid smart account](/delegation-toolkit/development/guides/smart-accounts/create-smart-account), and fund it with some Sepolia USDC to pay gas fees.
24-
:::note
25-
You can use [Circle's faucet](https://faucet.circle.com/) to get Sepolia USDC.
26-
:::
22+
- Install [Node.js](https://nodejs.org/en/blog/release/v18.18.0) v18 or later.
23+
- Install [Yarn](https://yarnpkg.com/),
24+
[npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), or another package manager.
2725
- [Create a Pimlico API key](https://docs.pimlico.io/guides/create-api-key#create-api-key).
2826

2927
## Steps
3028

31-
### 1. Create a Public Client
29+
### 1. Install the toolkit
30+
31+
Install the [MetaMask Delegation Toolkit](https://www.npmjs.com/package/@metamask/delegation-toolkit) in your project:
32+
33+
```bash npm2yarn
34+
npm install @metamask/delegation-toolkit
35+
```
36+
37+
### 2. Create a Public Client
3238

3339
Create a [Viem Public Client](https://viem.sh/docs/clients/public) using Viem's `createPublicClient` function.
3440
You will configure a smart account and Bundler Client with the Public Client, which you can use to query the signer's account state and interact with the blockchain network.
@@ -43,7 +49,7 @@ const publicClient = createPublicClient({
4349
});
4450
```
4551

46-
### 2. Create a Paymaster Client
52+
### 3. Create a Paymaster Client
4753

4854
Create a [Viem Paymaster Client](https://viem.sh/account-abstraction/clients/paymaster)
4955
using Viem's `createPaymasterClient` function. This client interacts with the paymaster service, enabling users to pay gas fees in USDC.
@@ -58,7 +64,7 @@ const paymasterClient = createPaymasterClient({
5864
});
5965
```
6066

61-
### 3. Create a Bundler Client
67+
### 4. Create a Bundler Client
6268

6369
Create a [Viem Bundler Client](https://viem.sh/account-abstraction/clients/bundler) using Viem's `createBundlerClient` function. You can use the bundler service to estimate gas for user operations and submit transactions to the network.
6470

@@ -80,9 +86,9 @@ const bundlerClient = createBundlerClient({
8086
});
8187
```
8288

83-
### 4. Create a Hybrid smart account
89+
### 5. Create and fund a smart account
8490

85-
Configure the same [Hybrid smart account](/delegation-toolkit/development/guides/smart-accounts/create-smart-account/#create-a-hybrid-smart-account) that you created and funded as a [prerequisite](#prerequisites).
91+
Create a [Hybrid smart account](/delegation-toolkit/development/guides/smart-accounts/create-smart-account/#create-a-hybrid-smart-account).
8692
A Hybrid smart account is a flexible smart account implementation that supports both an externally owned account (EOA) owner and any number of passkey (WebAuthn) signers.
8793

8894
```typescript
@@ -100,7 +106,13 @@ const smartAccount = await toMetaMaskSmartAccount({
100106
});
101107
```
102108

103-
### 5. Send a user operation
109+
Fund the account with some Sepolia USDC to pay gas fees.
110+
111+
:::note
112+
You can use [Circle's faucet](https://faucet.circle.com/) to get Sepolia USDC.
113+
:::
114+
115+
### 6. Send a user operation
104116

105117
The ERC-20 paymaster works by transferring the token from the smart account, and reimbursing itself for paying the gas fees on the user's behalf.
106118

@@ -117,7 +129,7 @@ Batch the approve call with other onchain actions you want to perform using the
117129
Pass the `paymasterClient` from [Step 2](#2-create-a-paymaster-client) to the `paymaster` property.
118130

119131
```typescript
120-
// Appropriate fee per gas must be determined for the specific bundler being used.
132+
// Appropriate fee per gas must be determined for the bundler being used.
121133
const maxFeePerGas = 1n;
122134
const maxPriorityFeePerGas = 1n;
123135

src/pages/tutorials/use-passkey-as-backup-signer.md

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,21 @@ This tutorial walks you through adding a passkey signer to an already deployed s
2323

2424
## Prerequisites
2525

26-
- [Install and set up the Delegation Toolkit](/delegation-toolkit/get-started/install) in your project.
27-
- [Install Ox SDK](https://oxlib.sh/#installation).
28-
- [Create and deploy a Hybrid smart account,](/delegation-toolkit/development/guides/smart-accounts/create-smart-account) with a signatory from a private key.
26+
- Install [Node.js](https://nodejs.org/en/blog/release/v18.18.0) v18 or later.
27+
- Install [Yarn](https://yarnpkg.com/),
28+
[npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), or another package manager.
2929

3030
## Steps
3131

32-
### 1. Create a Public Client
32+
### 1. Install dependencies
33+
34+
Install the [MetaMask Delegation Toolkit](https://www.npmjs.com/package/@metamask/delegation-toolkit) and [Ox SDK](https://oxlib.sh/#installation) in your project:
35+
36+
```bash npm2yarn
37+
npm install @metamask/delegation-toolkit ox
38+
```
39+
40+
### 2. Create a Public Client
3341

3442
Create a [Viem Public Client](https://viem.sh/docs/clients/public) using Viem's `createPublicClient` function.
3543
You will configure a smart account and Bundler Client with the Public Client, which you can use to query the signer's account state and interact with the blockchain network.
@@ -44,7 +52,7 @@ const publicClient = createPublicClient({
4452
})
4553
```
4654

47-
### 2. Create a Bundler Client
55+
### 3. Create a Bundler Client
4856

4957
Create a [Viem Bundler Client](https://viem.sh/account-abstraction/clients/bundler) using Viem's `createBundlerClient` function.
5058
You can use the bundler service to estimate gas for user operations and submit transactions to the network.
@@ -58,27 +66,41 @@ const bundlerClient = createBundlerClient({
5866
})
5967
```
6068

61-
### 3. Create a Hybrid smart account
69+
### 4. Create and deploy a smart account
6270

63-
Configure the same [Hybrid smart account](/delegation-toolkit/development/guides/smart-accounts/create-smart-account/#create-a-hybrid-smart-account) that you created and deployed as a [prerequisite](#prerequisites).
71+
Create and deploy a [Hybrid smart account](/delegation-toolkit/development/guides/smart-accounts/create-smart-account), with a private key signer.
6472
The Hybrid implementation supports adding additional passkey signers.
6573

6674
```typescript
6775
import { Implementation, toMetaMaskSmartAccount } from '@metamask/delegation-toolkit'
6876
import { privateKeyToAccount } from 'viem/accounts'
77+
import { zeroAddress } from 'viem'
6978

7079
const account = privateKeyToAccount('0x...')
7180

81+
// Create the smart account.
7282
const smartAccount = await toMetaMaskSmartAccount({
7383
client: publicClient,
7484
implementation: Implementation.Hybrid,
7585
deployParams: [account.address, [], [], []],
7686
deploySalt: '0x',
7787
signatory: { account },
7888
})
89+
90+
// Deploy the smart account by sending a user operation.
91+
// Appropriate fee per gas must be determined for the bundler being used.
92+
const maxFeePerGas = 1n;
93+
const maxPriorityFeePerGas = 1n;
94+
95+
const userOperationHash = await bundlerClient.sendUserOperation({
96+
account: smartAccount,
97+
calls: [{ to: zeroAddress }],
98+
maxFeePerGas,
99+
maxPriorityFeePerGas,
100+
})
79101
```
80102

81-
### 4. Create a passkey
103+
### 5. Create a passkey
82104

83105
To add a passkey signer, use Viem's [`createWebAuthnCredential`](https://viem.sh/account-abstraction/accounts/webauthn/createWebAuthnCredential) function to securely register the passkey (WebAuthn credential).
84106

@@ -90,7 +112,7 @@ const credential = await createWebAuthnCredential({
90112
})
91113
```
92114

93-
### 5. Add the passkey as a backup signer
115+
### 6. Add the passkey as a backup signer
94116

95117
Use the `HybridDeleGator` contract namespace from the Delegation Toolkit to encode the calldata required to add the passkey signer.
96118
The encoding function needs the X and Y coordinates of the P-256 public key.
@@ -115,7 +137,7 @@ const data = HybridDeleGator.encode.addKey({
115137
p256Owner,
116138
})
117139

118-
// Appropriate fee per gas must be determined for the specific bundler being used.
140+
// Appropriate fee per gas must be determined for the bundler being used.
119141
const maxFeePerGas = 1n
120142
const maxPriorityFeePerGas = 1n
121143

@@ -132,7 +154,7 @@ const userOperationHash = await bundlerClient.sendUserOperation({
132154
})
133155
```
134156

135-
### 6. (Optional) Use the passkey signer
157+
### 7. (Optional) Use the passkey signer
136158

137159
You can now use the passkey signer to access your smart account and sign transactions.
138160
If you ever lose your primary signer (private key) used in [Step 3](#3-create-a-hybrid-smart-account), you can use the passkey as a secure backup method to retain access to your smart account.

0 commit comments

Comments
 (0)