Skip to content

Commit 735cb0a

Browse files
Update DTK tutorials
* Update DTK tutorials * update prereqs
1 parent 2ef8bba commit 735cb0a

File tree

3 files changed

+72
-31
lines changed

3 files changed

+72
-31
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +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-
- [Configure the Delegation Toolkit.](/delegation-toolkit/development/guides/configure)
23-
- [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).
2425
- Get an [Infura API key](/developer-tools/dashboard/get-started/create-api) from the MetaMask Developer dashboard.
2526
- Have a MetaMask account with some Sepolia ETH to deploy your contract.
2627
:::note
@@ -29,7 +30,15 @@ In this tutorial, you'll create and apply a caveat enforcer that only allows a d
2930

3031
## Steps
3132

32-
### 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
3342

3443
At the root of your project, create a `contracts` directory.
3544
In that directory, create a new contract named `AfterTimestampEnforcer.sol`.
@@ -75,7 +84,7 @@ contract AfterTimestampEnforcer is CaveatEnforcer {
7584
}
7685
```
7786

78-
### 2. Deploy the caveat enforcer
87+
### 3. Deploy the caveat enforcer
7988

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

9099
The Forge CLI will display the address of the deployed caveat enforcer.
91100

92-
### 3. Apply the caveat enforcer
101+
### 4. Apply the caveat enforcer
93102

94103
Specify the address of the deployed `AfterTimestampEnforcer.sol` contract, add it to the caveat builder, and create a delegation.
95104
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 & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +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-
- [Configure the Delegation Toolkit](/delegation-toolkit/development/guides/configure).
24-
- [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.
25-
:::note
26-
You can use [Circle's faucet](https://faucet.circle.com/) to get Sepolia USDC.
27-
:::
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.
2825
- [Create a Pimlico API key](https://docs.pimlico.io/guides/create-api-key#create-api-key).
2926

3027
## Steps
3128

32-
### 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
3338

3439
Create a [Viem Public Client](https://viem.sh/docs/clients/public) using Viem's `createPublicClient` function.
3540
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 +49,7 @@ const publicClient = createPublicClient({
4449
});
4550
```
4651

47-
### 2. Create a Paymaster Client
52+
### 3. Create a Paymaster Client
4853

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

62-
### 3. Create a Bundler Client
67+
### 4. Create a Bundler Client
6368

6469
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.
6570

@@ -81,9 +86,9 @@ const bundlerClient = createBundlerClient({
8186
});
8287
```
8388

84-
### 4. Create a Hybrid smart account
89+
### 5. Create and fund a smart account
8590

86-
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).
8792
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.
8893

8994
```typescript
@@ -101,7 +106,13 @@ const smartAccount = await toMetaMaskSmartAccount({
101106
});
102107
```
103108

104-
### 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
105116

106117
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.
107118

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

120131
```typescript
121-
// 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.
122133
const maxFeePerGas = 1n;
123134
const maxPriorityFeePerGas = 1n;
124135

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

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +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-
- [Configure the Delegation Toolkit](/delegation-toolkit/development/guides/configure).
29-
- [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.
3029

3130
## Steps
3231

33-
### 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
3441

3542
Create a [Viem Public Client](https://viem.sh/docs/clients/public) using Viem's `createPublicClient` function.
3643
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.
@@ -45,7 +52,7 @@ const publicClient = createPublicClient({
4552
})
4653
```
4754

48-
### 2. Create a Bundler Client
55+
### 3. Create a Bundler Client
4956

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

62-
### 3. Create a Hybrid smart account
69+
### 4. Create and deploy a smart account
6370

64-
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.
6572
The Hybrid implementation supports adding additional passkey signers.
6673

6774
```typescript
6875
import { Implementation, toMetaMaskSmartAccount } from '@metamask/delegation-toolkit'
6976
import { privateKeyToAccount } from 'viem/accounts'
77+
import { zeroAddress } from 'viem'
7078

7179
const account = privateKeyToAccount('0x...')
7280

81+
// Create the smart account.
7382
const smartAccount = await toMetaMaskSmartAccount({
7483
client: publicClient,
7584
implementation: Implementation.Hybrid,
7685
deployParams: [account.address, [], [], []],
7786
deploySalt: '0x',
7887
signatory: { account },
7988
})
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+
})
80101
```
81102

82-
### 4. Create a passkey
103+
### 5. Create a passkey
83104

84105
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).
85106

@@ -91,7 +112,7 @@ const credential = await createWebAuthnCredential({
91112
})
92113
```
93114

94-
### 5. Add the passkey as a backup signer
115+
### 6. Add the passkey as a backup signer
95116

96117
Use the `HybridDeleGator` contract namespace from the Delegation Toolkit to encode the calldata required to add the passkey signer.
97118
The encoding function needs the X and Y coordinates of the P-256 public key.
@@ -116,7 +137,7 @@ const data = HybridDeleGator.encode.addKey({
116137
p256Owner,
117138
})
118139

119-
// 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.
120141
const maxFeePerGas = 1n
121142
const maxPriorityFeePerGas = 1n
122143

@@ -133,7 +154,7 @@ const userOperationHash = await bundlerClient.sendUserOperation({
133154
})
134155
```
135156

136-
### 6. (Optional) Use the passkey signer
157+
### 7. (Optional) Use the passkey signer
137158

138159
You can now use the passkey signer to access your smart account and sign transactions.
139160
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)