Skip to content

Commit d7e16d1

Browse files
committed
chore(docs): add docs for the erc20 paymaster capability
chore(docs): small feedback fixes chore(docs): claude code automated erc20 docs fixes chore(docs): simplify erc20 capability page chore(docs): claude code edits chore(docs): copilot suggested fixes docs: updating template chore(docs): more erc20 doc improvements chore(docs): more erc20 docs fixes chore(docs): erc20 docs feedback
1 parent 0d40024 commit d7e16d1

File tree

7 files changed

+483
-2
lines changed

7 files changed

+483
-2
lines changed

docs/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ navigation:
203203
- page: Sponsor gas
204204
path: wallets/pages/transactions/sponsor-gas.mdx
205205
- page: Pay gas with any token
206-
path: wallets/pages/transactions/pay-gas-with-any-token.mdx
206+
path: wallets/pages/transactions/pay-gas-with-any-token/index.mdx
207207
- page: "[NEW] Swap tokens"
208208
path: wallets/pages/transactions/swap-tokens.mdx
209209
- page: Send parallel transactions
@@ -260,7 +260,7 @@ navigation:
260260
path: wallets/pages/signer/as-an-eoa.mdx
261261
path: wallets/pages/TO-REMOVE-transactions/sponsor-gas/sponsor-gas-solana.mdx
262262
- page: Pay gas with any token
263-
path: wallets/pages/react/pay-gas-with-any-token.mdx
263+
path: wallets/pages/transactions/pay-gas-with-any-token/index.mdx
264264
- section: Using 7702
265265
contents:
266266
- page: Overview

docs/pages/transactions/pay-gas-with-any-token.mdx

Whitespace-only changes.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
See the [`wallet_prepareCalls` API
2+
reference](/docs/wallets/api/smart-wallets/wallet-api-endpoints/wallet-api-endpoints/wallet-prepare-calls)
3+
for full descriptions of the parameters used in the following example.
4+
5+
<Steps>
6+
<Step title="(If Needed) Request Account">
7+
If the user does not yet have a smart account, you must create one.
8+
```bash
9+
ACCOUNT_ADDRESS=$(curl --request POST \
10+
--url https://api.g.alchemy.com/v2/$ALCHEMY_API_KEY \
11+
--header 'accept: application/json' \
12+
--data '
13+
{
14+
"id": 1,
15+
"jsonrpc": "2.0",
16+
"method": "wallet_requestAccount",
17+
"params": [
18+
{
19+
"signerAddress": "'$SIGNER_ADDRESS'"
20+
}
21+
]
22+
}
23+
' | jq -r '.result.accountAddress')
24+
```
25+
</Step>
26+
<Step title="Prepare Calls">
27+
Prepare calls using the `paymasterService` capability.
28+
```bash
29+
curl --request POST \
30+
--url https://api.g.alchemy.com/v2/$ALCHEMY_API_KEY \
31+
--header 'accept: application/json' \
32+
--data '
33+
{
34+
"id": 1,
35+
"jsonrpc": "2.0",
36+
"method": "wallet_prepareCalls",
37+
"params": [
38+
{
39+
"capabilities": {
40+
"paymasterService": {
41+
"policyId": "'$ALCHEMY_POLICY_ID'",
42+
"erc20": {
43+
"tokenAddress": "'$GAS_TOKEN'",
44+
"postOpSettings": {
45+
"autoApprove": {
46+
"below": "'$APPROVE_BELOW'",
47+
"amount": "'$APPROVE_AMOUNT'"
48+
}
49+
}
50+
}
51+
}
52+
},
53+
"calls": [
54+
{
55+
"to": "0x0000000000000000000000000000000000000000"
56+
}
57+
],
58+
"from": "'$ACCOUNT_ADDRESS'",
59+
"chainId": "'$CHAIN_ID'"
60+
}
61+
]
62+
}'
63+
```
64+
</Step>
65+
<Step title="Sign & Send">
66+
Sign the returned signature request and send using `wallet_sendPreparedCalls`.
67+
</Step>
68+
</Steps>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<Steps>
2+
<Step title="(If Needed) Request Account">
3+
If the user does not yet have a smart account, you must create one.
4+
```bash
5+
ACCOUNT_ADDRESS=$(curl --request POST \
6+
--url https://api.g.alchemy.com/v2/$ALCHEMY_API_KEY \
7+
--header 'accept: application/json' \
8+
--data '
9+
{
10+
"id": 1,
11+
"jsonrpc": "2.0",
12+
"method": "wallet_requestAccount",
13+
"params": [
14+
{
15+
"signerAddress": "'$SIGNER_ADDRESS'"
16+
}
17+
]
18+
}
19+
' | jq -r '.result.accountAddress')
20+
```
21+
</Step>
22+
<Step title="Initial Prepare Calls">
23+
Prepare calls using the `paymasterService` capability.
24+
```bash
25+
curl --request POST \
26+
--url https://api.g.alchemy.com/v2/$ALCHEMY_API_KEY \
27+
--header 'accept: application/json' \
28+
--data '
29+
{
30+
"id": 1,
31+
"jsonrpc": "2.0",
32+
"method": "wallet_prepareCalls",
33+
"params": [
34+
{
35+
"capabilities": {
36+
"paymasterService": {
37+
"policyId": "'$ALCHEMY_POLICY_ID'",
38+
"erc20": {
39+
"tokenAddress": "'$GAS_TOKEN'",
40+
"preOpSettings": {
41+
"autoPermit": {
42+
"below": "'$APPROVE_BELOW'",
43+
"amount": "'$APPROVE_AMOUNT'"
44+
}
45+
}
46+
}
47+
}
48+
},
49+
"calls": [
50+
{
51+
"to": "0x0000000000000000000000000000000000000000"
52+
}
53+
],
54+
"from": "'$ACCOUNT_ADDRESS'",
55+
"chainId": "'$CHAIN_ID'"
56+
}
57+
]
58+
}'
59+
```
60+
</Step>
61+
<Step title="(If Needed) Sign Permit Request">
62+
If the response to step 2 is a type `paymaster-permit`, then the user must sign the signature request and return via a second call to `wallet_prepareCalls`. Else, skip to step 5.
63+
The `data` field on the `paymaster-permit` response contains a [Permit typed message](https://eips.ethereum.org/EIPS/eip-2612). It is recommended that the user
64+
checks the fields of this message prior to calculating its hash. The `signatureRequest` field on the `paymaster-permit` response is a required signature over the calculated
65+
hash. This is typically an ERC-712 typed signature envelope with a field for the hash to sign over.
66+
</Step>
67+
<Step title="(If Needed) Second Prepare Calls">
68+
After signing, another call to `wallet_prepareCalls` is needed to encode the permit into the operation. As a convenience, the `paymaster-permit` response type returns a `modifiedRequest`
69+
parameter that modifies the initial request with the permit details. The second request is the `modifiedRequest` with an additional `paymasterPermitSignature` field set to the
70+
signature from step 3. The user can also choose to recreate the request and set the corresponding fields in the `paymasterService` capability to the details returned in the permit signature.
71+
For example:
72+
```
73+
{
74+
"capabilities": {
75+
"paymasterService": {
76+
"erc20": {
77+
"preOp": {
78+
"permitDetails": {
79+
"value": "0x...",
80+
"deadline": "0x...",
81+
}
82+
}
83+
}
84+
}
85+
}
86+
... // same request as step 2
87+
"paymasterPermitSignature": "0x..."
88+
}
89+
```
90+
</Step>
91+
<Step title="Sign & Send">
92+
Sign and send the last prepared calls result as usual using `wallet_sendPreparedCalls`.
93+
</Step>
94+
</Steps>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<Info>Required SDK version: ^v4.61.0</Info>
2+
3+
See the [`sendCalls` SDK
4+
reference](/docs/wallets/reference/account-kit/wallet-client/functions/sendCalls)
5+
for full descriptions of the parameters used in the following example.
6+
7+
Use the `paymasterService` capability on the smart wallet client `sendCalls` or `prepareCalls` actions.
8+
9+
<CodeBlocks>
10+
11+
```ts twoslash title="sendCalls.ts"
12+
import { client, config } from "./client.ts";
13+
14+
const { preparedCallIds } = await client.sendCalls({
15+
capabilities: {
16+
paymasterService: {
17+
policyId: config.policyId,
18+
erc20: {
19+
tokenAddress: config.gasToken,
20+
postOpSettings: {
21+
autoApprove: {
22+
below: config.approveBelow,
23+
amount: config.approveAmount,
24+
},
25+
},
26+
},
27+
},
28+
},
29+
calls: [
30+
{
31+
to: "0x0000000000000000000000000000000000000000",
32+
value: "0x00",
33+
data: "0x",
34+
},
35+
],
36+
});
37+
```
38+
39+
```ts twoslash title="client.ts"
40+
import "dotenv/config";
41+
import { type Address, type Hex, toHex } from "viem";
42+
import { LocalAccountSigner } from "@aa-sdk/core";
43+
import { alchemy, sepolia } from "@account-kit/infra";
44+
import { createSmartWalletClient } from "@account-kit/wallet-client";
45+
46+
export const config = {
47+
policyId: process.env.ALCHEMY_POLICY_ID!,
48+
gasToken: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238" as Address, // USDC on sepolia
49+
approveBelow: toHex(1000000n), // 1 USDC
50+
approveAmount: toHex(10000000n), // 10 USDC
51+
};
52+
53+
const clientParams = {
54+
transport: alchemy({
55+
apiKey: process.env.ALCHEMY_API_KEY!,
56+
}),
57+
chain: sepolia,
58+
signer: LocalAccountSigner.privateKeyToAccountSigner(
59+
process.env.PRIVATE_KEY! as Hex,
60+
),
61+
};
62+
63+
const clientWithoutAccount = createSmartWalletClient(clientParams);
64+
65+
const account = await clientWithoutAccount.requestAccount();
66+
67+
export const client = createSmartWalletClient({
68+
...clientParams,
69+
account: account.address,
70+
});
71+
```
72+
73+
</CodeBlocks>

0 commit comments

Comments
 (0)