Skip to content

Commit 48f8111

Browse files
Improve delegation toolkit code snippets
* improve code snippets * update webAuthn code snippet * update Ox installation note Co-authored-by: Alexandra Carrillo <[email protected]> * Update permissionless.js installation info Co-authored-by: Alexandra Carrillo <[email protected]> * remove linea from supported networks --------- Co-authored-by: Alexandra Carrillo <[email protected]>
1 parent 3b885a5 commit 48f8111

File tree

4 files changed

+44
-30
lines changed

4 files changed

+44
-30
lines changed

delegation-toolkit/get-started/quickstart.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,7 @@ import { zeroAddress } from "viem";
146146

147147
const delegations = [ signedDelegation ];
148148

149-
const executions = [{
150-
target: zeroAddress,
151-
value: 0n,
152-
callData: "0x"
153-
}];
149+
const executions = createExecution(zeroAddress);
154150

155151
const redeemDelegationCalldata = DelegationFramework.encode.redeemDelegations({
156152
delegations: [ delegations ],

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ If you don't see the network you're looking for, you can request support by emai
1818
| Binance Smart Chain ||||
1919
| Optimism ||||
2020
| Arbitrum ||||
21-
| Linea ||||
2221
| Base ||||
2322
| Gnosis Chain ||||
2423

@@ -27,7 +26,6 @@ If you don't see the network you're looking for, you can request support by emai
2726
| Network Name | v0.10.1 | v0.10.2 | v0.11.0 |
2827
| ---------------- | ------- | ------- | ------- |
2928
| Ethereum Sepolia ||||
30-
| Linea Sepolia ||||
3129
| Base Sepolia ||||
3230
| MegaEth ||||
3331
| Gnosis Chiado ||||

delegation-toolkit/how-to/create-smart-account/configure-accounts-signers.md

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ This example creates a signatory from a private key using Viem's [`privateKeyToA
4848

4949
```typescript
5050
import { publicClient } from "./client.ts"
51-
import { signatory } from "./signatory.ts";
51+
import { account } from "./signatory.ts";
5252
import {
5353
Implementation,
5454
toMetaMaskSmartAccount,
@@ -57,9 +57,9 @@ import {
5757
const smartAccount = await toMetaMaskSmartAccount({
5858
client: publicClient,
5959
implementation: Implementation.Hybrid,
60-
deployParams: [owner, p256KeyIds, p256XValues, p256YValues],
60+
deployParams: [account.address, [], [], []],
6161
deploySalt: "0x",
62-
signatory,
62+
signatory: { account },
6363
});
6464
```
6565

@@ -86,9 +86,7 @@ export const publicClient = createPublicClient({
8686
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
8787

8888
const privateKey = generatePrivateKey();
89-
const account = privateKeyToAccount(privateKey);
90-
91-
export const signatory = { account };
89+
export const account = privateKeyToAccount(privateKey);
9290
```
9391

9492
</TabItem>
@@ -104,18 +102,21 @@ using Viem's `createWalletClient` function.
104102

105103
```typescript
106104
import { publicClient } from "./client.ts"
107-
import { signatory } from "./signatory.ts";
105+
import { walletClient } from "./signatory.ts";
108106
import {
109107
Implementation,
110108
toMetaMaskSmartAccount,
111109
} from "@metamask/delegation-toolkit";
112110

111+
const addresses = await walletClient.getAddresses();
112+
const owner = addresses[0];
113+
113114
const smartAccount = await toMetaMaskSmartAccount({
114115
client: publicClient,
115116
implementation: Implementation.Hybrid,
116-
deployParams: [owner, p256KeyIds, p256XValues, p256YValues],
117+
deployParams: [owner, [], [], []],
117118
deploySalt: "0x",
118-
signatory,
119+
signatory: { walletClient },
119120
});
120121
```
121122

@@ -146,13 +147,11 @@ import { http, createWalletClient } from "viem";
146147
const privateKey = generatePrivateKey();
147148
const account = privateKeyToAccount(privateKey);
148149

149-
const walletClient = createWalletClient({
150+
export const walletClient = createWalletClient({
150151
account,
151152
chain,
152153
transport: http()
153154
})
154-
155-
export const signatory = { walletClient };
156155
```
157156

158157
</TabItem>
@@ -163,23 +162,37 @@ export const signatory = { walletClient };
163162
This example creates a [Viem WebAuthn Account](https://viem.sh/account-abstraction/accounts/webauthn) as the signatory,
164163
using Viem's `toWebAuthnAccount` function.
165164

165+
:::info Installation required
166+
167+
To work with WebAuthn, install the [Ox SDK](https://oxlib.sh/).
168+
169+
:::
170+
166171
<Tabs>
167172
<TabItem value="example.ts">
168173

169174
```typescript
170175
import { publicClient } from "./client.ts"
171-
import { signatory } from "./signatory.ts";
176+
import { webAuthnAccount, credential } from "./signatory.ts";
172177
import {
173178
Implementation,
174179
toMetaMaskSmartAccount,
175180
} from "@metamask/delegation-toolkit";
181+
import { Address, PublicKey } from "ox";
182+
import { toHex } from "viem";
183+
184+
// Deserialize compressed public key
185+
const publicKey = PublicKey.fromHex(credential.publicKey);
186+
187+
// Convert public key to address
188+
const owner = Address.fromPublicKey(publicKey);
176189

177190
const smartAccount = await toMetaMaskSmartAccount({
178191
client: publicClient,
179192
implementation: Implementation.Hybrid,
180-
deployParams: [owner, p256KeyIds, p256XValues, p256YValues],
193+
deployParams: [owner, [credential.id], [publicKey.x], [publicKey.y]],
181194
deploySalt: "0x",
182-
signatory,
195+
signatory: { webAuthnAccount, keyId: toHex(credential.id) },
183196
});
184197
```
185198

@@ -203,15 +216,16 @@ export const publicClient = createPublicClient({
203216
<TabItem value="signatory.ts">
204217

205218
```typescript
206-
import { createCredential, parsePublicKey } from "webauthn-p256";
207-
import { toWebAuthnAccount } from "viem/account-abstraction";
208-
import { toHex } from "viem";
209-
210-
const credential = await createCredential({ name: "Your Delegator Passkey" });
211-
const webAuthnAccount = toWebAuthnAccount({ credential });
212-
const keyId = toHex("my-key-id");
219+
import {
220+
createWebAuthnCredential,
221+
toWebAuthnAccount,
222+
} from "viem/account-abstraction";
213223

214-
const signatory = { webAuthnAccount, keyId };
224+
export const credential = await createWebAuthnCredential({
225+
name: "MetaMask Smart Account",
226+
});
227+
228+
export const webAuthnAccount = toWebAuthnAccount({ credential });
215229
```
216230

217231
</TabItem>

delegation-toolkit/how-to/send-user-operation.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ The following example updates the previous example to estimate the fees.
109109
This example uses constant values, but the [Hello Gator example](https://github.com/MetaMask/hello-gator) uses Pimlico's Alto bundler,
110110
which fetches user operation gas price using the RPC method [`pimlico_getUserOperationPrice`](https://docs.pimlico.io/infra/bundler/endpoints/pimlico_getUserOperationGasPrice).
111111

112+
:::info Installation required
113+
114+
To estimate the gas fee using Pimlico's bundler, install the [permissionless.js SDK](https://docs.pimlico.io/references/permissionless/).
115+
116+
:::
117+
112118
```typescript title="example.ts"
113119
// add-next-line
114120
+ import { createPimlicoClient } from "permissionless/clients/pimlico";

0 commit comments

Comments
 (0)