Skip to content

Commit ffc1d2e

Browse files
authored
feat: gelato account support erc4337 (#23)
1 parent bebe27b commit ffc1d2e

4 files changed

Lines changed: 24 additions & 11 deletions

File tree

examples/account/sponsored/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { resolve } from 'node:path';
12
import { config } from 'dotenv';
2-
import { resolve } from 'path';
33

44
// Load root .env first (defaults)
55
config({ path: resolve(__dirname, '../../../../.env') });

examples/bundler/sponsored/src/index.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
import { resolve } from 'node:path';
12
import { config } from 'dotenv';
2-
import { resolve } from 'path';
33

44
// Load root .env first (defaults)
55
config({ path: resolve(__dirname, '../../../../.env') });
66

77
// Load local .env to override (optional)
88
config({ override: true });
99

10-
import { createGelatoBundlerClient, sponsored } from '@gelatocloud/gasless';
11-
import { toKernelSmartAccount } from 'permissionless/accounts';
12-
import { createPublicClient, type Hex, http } from 'viem';
10+
import { createGelatoBundlerClient, sponsored, toGelatoSmartAccount } from '@gelatocloud/gasless';
11+
import { createPublicClient, type Hex, http, type SignedAuthorization } from 'viem';
1312
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
1413
import { baseSepolia } from 'viem/chains';
1514

@@ -30,11 +29,9 @@ const main = async () => {
3029
transport: http()
3130
});
3231

33-
const account = await toKernelSmartAccount({
32+
const account = toGelatoSmartAccount({
3433
client,
35-
owners: [owner],
36-
useMetaFactory: false,
37-
version: '0.3.3'
34+
owner
3835
});
3936

4037
const bundler = await createGelatoBundlerClient({
@@ -45,7 +42,22 @@ const main = async () => {
4542
pollingInterval: 100
4643
});
4744

45+
const deployed = await account.isDeployed();
46+
47+
let authorization: SignedAuthorization | undefined;
48+
49+
if (!deployed) {
50+
const nonce = await client.getTransactionCount({ address: owner.address });
51+
52+
authorization = await owner.signAuthorization({
53+
address: account.authorization.address,
54+
chainId: chain.id,
55+
nonce
56+
});
57+
}
58+
4859
const hash = await bundler.sendUserOperation({
60+
authorization,
4961
calls: [
5062
{
5163
data: '0xd09de08a',

examples/relayer/sponsored/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { resolve } from 'node:path';
12
import { config } from 'dotenv';
2-
import { resolve } from 'path';
33

44
// Load root .env first (defaults)
55
config({ path: resolve(__dirname, '../../../../.env') });

src/account/adapters/gelato/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
encodePacked,
77
type JsonRpcAccount,
88
type LocalAccount,
9+
type PrivateKeyAccount,
910
type StateOverride,
1011
type Transport,
1112
type TypedDataDefinition
@@ -84,7 +85,7 @@ export const toGelatoSmartAccount = (
8485
return {
8586
address: owner.address,
8687
authorization: {
87-
account: undefined as never,
88+
account: owner as PrivateKeyAccount,
8889
address: GELATO_DELEGATION_ADDRESS
8990
},
9091
chain: client.chain,

0 commit comments

Comments
 (0)