Skip to content

Commit 8046d58

Browse files
ft: adding docs for @etherspot/free-bundler sdk
1 parent 0b97601 commit 8046d58

File tree

4 files changed

+265
-0
lines changed

4 files changed

+265
-0
lines changed

docs/userops/basic.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#Send First Userop
2+
3+
This guide will help understanding how to broadcast a [7702](https://eip7702.io/) userop using smart wallet implemented [here](https://github.com/eth-infinitism/account-abstraction/blob/develop/contracts/accounts/Simple7702Account.sol)
4+
5+
### 1. Create Smart Account Client
6+
Refer [here](https://viem.sh/account-abstraction/accounts/smart#smart-accounts) to understand how to create different smart account clients. **Only use wallets which support entrypoint v0.8**
7+
=== "account.ts"
8+
```ts
9+
import { commonClient } from './client'
10+
import { toSimple7702SmartAccount } from 'viem/account-abstraction'
11+
import { privateKeyToAccount } from 'viem/accounts'
12+
const owner = privateKeyToAccount('0x...') // add private key here
13+
14+
export const smartAccount = await toSimple7702SmartAccount({
15+
client: commonClient,
16+
owner,
17+
});
18+
```
19+
=== "client.ts"
20+
```ts
21+
import { createFreeBundler } from '@etherspot/free-bundler'
22+
import { publicActions, walletActions } from 'viem'
23+
import { mainnet } from 'viem/chains'
24+
const chain = mainnet
25+
26+
export const commonClient = createFreeBundler({chain})
27+
.extend(publicActions)
28+
.extend(walletActions)
29+
```
30+
31+
### 2. Send Userop
32+
=== "example.ts"
33+
```ts
34+
import { commonClient } from './client'
35+
import { toSimple7702SmartAccount } from 'viem/account-abstraction'
36+
import { privateKeyToAccount } from 'viem/accounts'
37+
import { SignAuthorizationReturnType } from 'viem'
38+
39+
const owner = privateKeyToAccount('0x...') // add private key here
40+
41+
const smartAccount = await toSimple7702SmartAccount({
42+
client: commonClient,
43+
owner,
44+
})
45+
46+
console.log("wallet:: ", smartAccount.address)
47+
48+
// check sender's code to decide if eip7702Auth tuple is necessary for userOp.
49+
const senderCode = await commonClient.getCode({
50+
address: smartAccount.address
51+
})
52+
53+
let authorization: SignAuthorizationReturnType | undefined
54+
const { address: delegateAddress } = smartAccount.authorization
55+
56+
if(senderCode !== `0xef0100${delegateAddress.toLowerCase().substring(2)}`) {
57+
authorization = await commonClient.signAuthorization(smartAccount.authorization)
58+
}
59+
60+
const userOpHash = await commonClient.sendUserOperation({
61+
account: smartAccount,
62+
authorization,
63+
calls: [
64+
{
65+
to: "0x09FD4F6088f2025427AB1e89257A44747081Ed59",
66+
value: parseUnits('0.0000001', 18)
67+
}
68+
]
69+
})
70+
71+
console.log('userOpHash:: ', userOpHash)
72+
```
73+
=== "client.ts"
74+
```ts
75+
import { createFreeBundler } from '@etherspot/free-bundler'
76+
import { publicActions, walletActions } from 'viem'
77+
import { mainnet } from 'viem/chains'
78+
const chain = mainnet
79+
80+
export const commonClient = createFreeBundler({chain})
81+
.extend(publicActions)
82+
.extend(walletActions)
83+
```
84+
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/etherspot/free-bundler?file=examples%2Findex.ts)
85+
86+
After opening StackBlitz, run:
87+
```bash
88+
npx tsx examples/index.ts --private-key 0x...
89+
```
90+
<small><em>For more run options, see the <a href="https://github.com/etherspot/free-bundler/blob/master/examples/USAGE.md">GitHub examples usage</a>.</em></small>

docs/userops/quick-start.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Quick Start Guide
2+
3+
Get up and running with EntryPoint v0.8 and 7702 UserOperations in under 5 minutes! This guide will walk you through with installing the necessary dependencies and creating bundler client.
4+
5+
## Installation
6+
7+
### Install Required Packages
8+
9+
```bash
10+
npm i @etherspot/free-bundler
11+
# or
12+
yarn add @etherspot/free-bundler
13+
# or
14+
bun add @etherspot/free-bundler
15+
```
16+
17+
## Getting Started
18+
19+
### 1. Get list of all supported networks (including testnets)
20+
```typescript
21+
import {getSupportedChainIds} from '@etherspot/free-bundler';
22+
23+
const supportedChainIds = getSupportedChainIds();
24+
```
25+
26+
### 2. Get common bundler and rpc url for a given chain id
27+
```typescript
28+
import { getFreeBundlerUrl } from '@etherspot/free-bundler';
29+
30+
const chainId = 1;
31+
const bundlerAndRpcUrl = getFreeBundlerUrl(chainId);
32+
```
33+
34+
### 3. Create bundler client
35+
Refer [here](https://viem.sh/account-abstraction/actions/bundler/estimateUserOperationGas) for more actions using bundler client which involves eth_estimateUserOperationGas, eth_sendUserOperation etc.
36+
```typescript
37+
import { createFreeBundler } from '@etherspot/free-bundler';
38+
import { publicActions, walletActions } from 'viem';
39+
import { mainnet } from "viem/chains";
40+
41+
const chain = mainnet;
42+
const bundlerClient = createFreeBundler({chain});
43+
44+
// optionally extend the client to use public and wallet actions
45+
const commonClient = createFreeBundler({chain})
46+
.extend(publicActions)
47+
.extend(walletActions);
48+
```
49+
50+
1. **[Constructing UserOps](../userops/basic.md)** - Create and Send UserOp
51+
52+
---

docs/userops/sponsor.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#Sponsored Userop
2+
3+
This guide will help understanding how to broadcast a [7702](https://eip7702.io/) sponsored userop using smart wallet implemented [here](https://github.com/eth-infinitism/account-abstraction/blob/develop/contracts/accounts/Simple7702Account.sol) using free bundler client and a paymaster client.
4+
5+
### 1. Create Smart Account Client
6+
=== "account.ts"
7+
```ts
8+
import { commonClient } from './client'
9+
import { toSimple7702SmartAccount } from 'viem/account-abstraction'
10+
import { privateKeyToAccount } from 'viem/accounts'
11+
const owner = privateKeyToAccount('0x...') // add private key here
12+
13+
export const smartAccount = await toSimple7702SmartAccount({
14+
client: commonClient,
15+
owner,
16+
});
17+
```
18+
=== "client.ts"
19+
```ts
20+
import { createFreeBundler } from '@etherspot/free-bundler'
21+
import { publicActions, walletActions } from 'viem'
22+
import { mainnet } from 'viem/chains'
23+
const chain = mainnet
24+
25+
export const commonClient = createFreeBundler({chain})
26+
.extend(publicActions)
27+
.extend(walletActions)
28+
```
29+
30+
### 2. Create Paymaster client
31+
Refer [here](https://viem.sh/account-abstraction/clients/paymaster) for more options and detailed docs for paymaster client
32+
=== "paymaster.ts"
33+
```ts
34+
import { createPaymasterClient } from "viem/account-abstraction"
35+
36+
export const paymasterClient = createPaymasterClient({
37+
transport: http("") // add paymaster url here
38+
});
39+
40+
// NOTE: this can change according to the paymaster implementation.
41+
// use the corresponding paymaster's docs to understand what has to used for context.
42+
export const paymasterContext = { policyId: "" } // add policy id here
43+
```
44+
45+
### 3. Send Userop
46+
=== "example.ts"
47+
```ts
48+
import { commonClient } from './client'
49+
import { toSimple7702SmartAccount } from 'viem/account-abstraction'
50+
import { privateKeyToAccount } from 'viem/accounts'
51+
import { SignAuthorizationReturnType } from 'viem'
52+
import { paymasterClient, paymasterContext } from './paymaster'
53+
54+
const owner = privateKeyToAccount('0x...') // add private key here
55+
56+
const smartAccount = await toSimple7702SmartAccount({
57+
client: commonClient,
58+
owner,
59+
})
60+
61+
console.log("wallet:: ", smartAccount.address)
62+
63+
// check sender's code to decide if eip7702Auth tuple is necessary for userOp.
64+
const senderCode = await commonClient.getCode({
65+
address: smartAccount.address
66+
})
67+
68+
let authorization: SignAuthorizationReturnType | undefined
69+
const { address: delegateAddress } = smartAccount.authorization
70+
71+
if(senderCode !== `0xef0100${delegateAddress.toLowerCase().substring(2)}`) {
72+
authorization = await commonClient.signAuthorization(smartAccount.authorization)
73+
}
74+
75+
const userOpHash = await commonClient.sendUserOperation({
76+
account: smartAccount,
77+
authorization,
78+
calls: [
79+
{to: "0x09FD4F6088f2025427AB1e89257A44747081Ed59", value: parseUnits('0.0000001', 18)}
80+
],
81+
paymaster: paymasterClient,
82+
paymasterContext: paymasterContext ? JSON.parse(paymasterContext) : undefined,
83+
});
84+
85+
console.log('userOpHash:: ', userOpHash)
86+
```
87+
=== "client.ts"
88+
```ts
89+
import { createFreeBundler } from '@etherspot/free-bundler'
90+
import { publicActions, walletActions } from 'viem'
91+
import { mainnet } from 'viem/chains'
92+
const chain = mainnet
93+
94+
export const commonClient = createFreeBundler({chain})
95+
.extend(publicActions)
96+
.extend(walletActions)
97+
```
98+
=== "paymaster.ts"
99+
```ts
100+
import { createPaymasterClient } from "viem/account-abstraction"
101+
102+
export const paymasterClient = createPaymasterClient({
103+
transport: http("") // add paymaster url here
104+
});
105+
106+
// NOTE: this can change according to the paymaster implementation.
107+
// use the corresponding paymaster's docs to understand what has to used for context.
108+
export const paymasterContext = { policyId: "" } // add policy id here
109+
```
110+
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/etherspot/free-bundler?file=examples%2Findex.ts)
111+
112+
After opening StackBlitz, run:
113+
```bash
114+
npx tsx examples/index.ts \
115+
--private-key 0x... \
116+
--paymaster-url 'https://....' \
117+
--paymaster-context ''
118+
```
119+
<small><em>For more run options, see the <a href="https://github.com/etherspot/free-bundler/blob/master/examples/USAGE.md">GitHub examples usage</a>.</em></small>

mkdocs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ nav:
4949
- resources/reading-material.md
5050
- resources/videos.md
5151
- resources/faqs.md
52+
- "⚙️ Userops Guide":
53+
- userops/quick-start.md
54+
- userops/basic.md
55+
- userops/sponsor.md
5256

5357
theme:
5458
name: material

0 commit comments

Comments
 (0)