Skip to content

Commit eb7232f

Browse files
authored
Merge pull request #65 from cometh-hq/develop
Develop
2 parents 5e064ff + bd4bec5 commit eb7232f

File tree

11 files changed

+455
-440
lines changed

11 files changed

+455
-440
lines changed

examples/viem-demo/src/app/components/Transaction.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
getContract,
1111
parseEther,
1212
} from "viem";
13-
import { arbitrumSepolia } from "viem/chains";
13+
import { baseSepolia } from "viem/chains";
1414
import countContractAbi from "../contract/counterABI.json";
1515
import { Icons } from "../lib/ui/components";
1616
import Alert from "../lib/ui/components/Alert";
@@ -19,7 +19,7 @@ export const COUNTER_CONTRACT_ADDRESS =
1919
"0x4FbF9EE4B2AF774D4617eAb027ac2901a41a7b5F";
2020

2121
const publicClient = createPublicClient({
22-
chain: arbitrumSepolia,
22+
chain: baseSepolia,
2323
transport: http(),
2424
cacheTime: 60_000,
2525
batch: {

examples/viem-demo/src/app/components/TransactionWithSessionKey.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
encodeFunctionData,
1010
getContract,
1111
} from "viem";
12-
import { arbitrumSepolia } from "viem/chains";
12+
import { baseSepolia } from "viem/chains";
1313
import countContractAbi from "../contract/counterABI.json";
1414
import { Icons } from "../lib/ui/components";
1515
import Alert from "../lib/ui/components/Alert";
@@ -30,7 +30,7 @@ const bundlerUrl = process.env.NEXT_PUBLIC_4337_BUNDLER_URL;
3030
const paymasterUrl = process.env.NEXT_PUBLIC_4337_PAYMASTER_URL;
3131

3232
const publicClient = createPublicClient({
33-
chain: arbitrumSepolia,
33+
chain: baseSepolia,
3434
transport: http(),
3535
cacheTime: 60_000,
3636
batch: {
@@ -140,19 +140,19 @@ function TransactionWithSessionKey({
140140

141141
const sessionKeyAccount = await createSafeSmartAccount({
142142
apiKey,
143-
chain: arbitrumSepolia,
143+
chain: baseSepolia,
144144
smartAccountAddress: smartAccount?.account?.address,
145145
smartSessionSigner: sessionKeySigner,
146146
});
147147

148148
const paymasterClient = await createComethPaymasterClient({
149149
transport: http(paymasterUrl),
150-
chain: arbitrumSepolia,
150+
chain: baseSepolia,
151151
});
152152

153153
const sessionKeyClient = createSmartAccountClient({
154154
account: sessionKeyAccount,
155-
chain: arbitrumSepolia,
155+
chain: baseSepolia,
156156
bundlerTransport: http(bundlerUrl),
157157
paymaster: paymasterClient,
158158
userOperation: {
Lines changed: 110 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,125 @@
11
"use client";
22

33
import {
4-
ENTRYPOINT_ADDRESS_V07,
5-
createComethPaymasterClient,
6-
createSafeSmartAccount,
7-
createSmartAccountClient,
8-
importSafeActions,
4+
createComethPaymasterClient,
5+
createSafeSmartAccount,
6+
createSmartAccountClient,
7+
importSafeActions,
98
} from "@cometh/connect-sdk-4337";
109
import { http, type Hex, encodeFunctionData } from "viem";
1110
import { privateKeyToAccount } from "viem/accounts";
1211
import { gnosis } from "viem/chains";
1312
import countContractAbi from "../contract/counterABI.json";
1413

1514
export const COUNTER_CONTRACT_ADDRESS =
16-
"0x4FbF9EE4B2AF774D4617eAb027ac2901a41a7b5F";
15+
"0x4FbF9EE4B2AF774D4617eAb027ac2901a41a7b5F";
1716

1817
export default function App() {
19-
const apiKey = process.env.NEXT_PUBLIC_COMETH_API_KEY!;
20-
const bundlerUrl = process.env.NEXT_PUBLIC_4337_BUNDLER_URL!;
21-
const paymasterUrl = process.env.NEXT_PUBLIC_4337_PAYMASTER_URL!;
22-
const walletToImport = "0x";
23-
24-
const migrateSafe = async () => {
25-
const legacyWalletAddress = walletToImport;
26-
27-
const signer = privateKeyToAccount(
28-
process.env.NEXT_PUBLIC_PRIVATE_KEY! as Hex
29-
);
30-
31-
const safe4337SmartAccount = await createSafeSmartAccount({
32-
apiKey,
33-
chain: gnosis,
34-
smartAccountAddress: legacyWalletAddress,
35-
entryPoint: ENTRYPOINT_ADDRESS_V07,
36-
signer,
37-
});
38-
39-
const paymasterClient = await createComethPaymasterClient({
40-
transport: http(paymasterUrl),
41-
chain: gnosis,
42-
entryPoint: ENTRYPOINT_ADDRESS_V07,
43-
});
44-
const smartAccountClient = createSmartAccountClient({
45-
account: safe4337SmartAccount,
46-
entryPoint: ENTRYPOINT_ADDRESS_V07,
47-
chain: gnosis,
48-
bundlerTransport: http(bundlerUrl, {
49-
retryCount: 10,
50-
retryDelay: 200,
51-
}),
52-
middleware: {
53-
sponsorUserOperation: paymasterClient.sponsorUserOperation,
54-
gasPrice: paymasterClient.gasPrice,
55-
},
56-
});
57-
58-
const extendedClient = smartAccountClient.extend(importSafeActions());
59-
60-
const importMessage = await extendedClient.prepareImportSafe1_4Tx();
61-
62-
const signature = (await extendedClient.signTransactionByExternalOwner({
63-
signer,
64-
tx: importMessage.tx,
65-
})) as Hex;
66-
67-
await extendedClient.importSafe({
68-
signature,
69-
...importMessage,
70-
});
71-
72-
const safe4337SmartAccountImported = await createSafeSmartAccount({
73-
apiKey,
74-
chain: gnosis,
75-
smartAccountAddress: legacyWalletAddress,
76-
entryPoint: ENTRYPOINT_ADDRESS_V07,
77-
});
78-
79-
const smartAccountClientImported = createSmartAccountClient({
80-
account: safe4337SmartAccountImported,
81-
entryPoint: ENTRYPOINT_ADDRESS_V07,
82-
chain: gnosis,
83-
bundlerTransport: http(bundlerUrl, {
84-
retryCount: 10,
85-
retryDelay: 200,
86-
}),
87-
middleware: {
88-
sponsorUserOperation: paymasterClient.sponsorUserOperation,
89-
gasPrice: paymasterClient.gasPrice,
90-
},
91-
});
92-
93-
const calldata = encodeFunctionData({
94-
abi: countContractAbi,
95-
functionName: "count",
96-
});
97-
98-
const txHash = await smartAccountClientImported.sendTransaction({
99-
to: COUNTER_CONTRACT_ADDRESS,
100-
data: calldata,
101-
});
102-
103-
console.log("Transaction hash:", txHash);
104-
};
105-
106-
return (
107-
<div
108-
style={{
109-
height: "100vh",
110-
display: "flex",
111-
flexDirection: "column",
112-
justifyContent: "center",
113-
alignItems: "center",
114-
}}
115-
>
116-
<div className="md:min-h-[70vh] gap-2 flex flex-col justify-center items-center">
117-
<div className="absolute left-1/2 z-10 mt-5 flex w-screen max-w-max -translate-x-1/2 px-4">
118-
<div className="w-screen max-w-md flex-auto overflow-hidden rounded-3xl bg-white text-sm leading-6 shadow-lg ring-1 ring-gray-900/5">
119-
<div className="grid divide-gray-900/5 bg-gray-50">
120-
<button onClick={migrateSafe}>Migrate Safe</button>
121-
</div>
122-
</div>
123-
</div>
18+
const apiKey = process.env.NEXT_PUBLIC_COMETH_API_KEY!;
19+
const bundlerUrl = process.env.NEXT_PUBLIC_4337_BUNDLER_URL!;
20+
const paymasterUrl = process.env.NEXT_PUBLIC_4337_PAYMASTER_URL!;
21+
const walletToImport = "0x";
22+
23+
const migrateSafe = async () => {
24+
const legacyWalletAddress = walletToImport;
25+
26+
const signer = privateKeyToAccount(
27+
process.env.NEXT_PUBLIC_PRIVATE_KEY! as Hex
28+
);
29+
30+
const safe4337SmartAccount = await createSafeSmartAccount({
31+
apiKey,
32+
chain: gnosis,
33+
smartAccountAddress: legacyWalletAddress,
34+
signer,
35+
});
36+
37+
const paymasterClient = await createComethPaymasterClient({
38+
transport: http(paymasterUrl),
39+
chain: gnosis,
40+
});
41+
const smartAccountClient = createSmartAccountClient({
42+
account: safe4337SmartAccount,
43+
chain: gnosis,
44+
bundlerTransport: http(bundlerUrl, {
45+
retryCount: 10,
46+
retryDelay: 200,
47+
}),
48+
paymaster: paymasterClient,
49+
userOperation: {
50+
estimateFeesPerGas: async () => {
51+
return await paymasterClient.getUserOperationGasPrice();
52+
},
53+
},
54+
});
55+
56+
const extendedClient = smartAccountClient.extend(importSafeActions());
57+
58+
const importMessage = await extendedClient.prepareImportSafe1_4Tx();
59+
60+
const signature = (await extendedClient.signTransactionByExternalOwner({
61+
signer,
62+
tx: importMessage.tx,
63+
})) as Hex;
64+
65+
await extendedClient.importSafe({
66+
signature,
67+
...importMessage,
68+
});
69+
70+
const safe4337SmartAccountImported = await createSafeSmartAccount({
71+
apiKey,
72+
chain: gnosis,
73+
smartAccountAddress: legacyWalletAddress,
74+
});
75+
76+
const smartAccountClientImported = createSmartAccountClient({
77+
account: safe4337SmartAccountImported,
78+
chain: gnosis,
79+
bundlerTransport: http(bundlerUrl, {
80+
retryCount: 10,
81+
retryDelay: 200,
82+
}),
83+
paymaster: paymasterClient,
84+
userOperation: {
85+
estimateFeesPerGas: async () => {
86+
return await paymasterClient.getUserOperationGasPrice();
87+
},
88+
},
89+
});
90+
91+
const calldata = encodeFunctionData({
92+
abi: countContractAbi,
93+
functionName: "count",
94+
});
95+
96+
const txHash = await smartAccountClientImported.sendTransaction({
97+
to: COUNTER_CONTRACT_ADDRESS,
98+
data: calldata,
99+
});
100+
101+
console.log("Transaction hash:", txHash);
102+
};
103+
104+
return (
105+
<div
106+
style={{
107+
height: "100vh",
108+
display: "flex",
109+
flexDirection: "column",
110+
justifyContent: "center",
111+
alignItems: "center",
112+
}}
113+
>
114+
<div className="md:min-h-[70vh] gap-2 flex flex-col justify-center items-center">
115+
<div className="absolute left-1/2 z-10 mt-5 flex w-screen max-w-max -translate-x-1/2 px-4">
116+
<div className="w-screen max-w-md flex-auto overflow-hidden rounded-3xl bg-white text-sm leading-6 shadow-lg ring-1 ring-gray-900/5">
117+
<div className="grid divide-gray-900/5 bg-gray-50">
118+
<button onClick={migrateSafe}>Migrate Safe</button>
124119
</div>
120+
</div>
125121
</div>
126-
);
122+
</div>
123+
</div>
124+
);
127125
}

examples/viem-demo/src/app/modules/hooks/useSessionKey.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ export function useSessionKey() {
5151
sessionRequestedInfo: [
5252
{
5353
sessionPublicKey: sessionOwner.address,
54-
actionPoliciesInfo: [
55-
{
56-
contractAddress: COUNTER_CONTRACT_ADDRESS,
57-
functionSelector: toFunctionSelector(
58-
"function count()"
59-
) as Hex,
60-
},
61-
],
54+
/* actionPoliciesInfo: [
55+
{
56+
contractAddress: COUNTER_CONTRACT_ADDRESS,
57+
functionSelector: toFunctionSelector(
58+
"function count()"
59+
) as Hex,
60+
},
61+
], */
6262
},
6363
],
6464
});

examples/viem-demo/src/app/modules/hooks/useSmartAccount.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from "@cometh/connect-sdk-4337";
99
import { useState } from "react";
1010
import { http, type Hex, type PublicClient, createPublicClient } from "viem";
11-
import { arbitrumSepolia } from "viem/chains";
11+
import { baseSepolia } from "viem/chains";
1212

1313
export function useSmartAccount() {
1414
const [isConnecting, setIsConnecting] = useState(false);
@@ -39,7 +39,7 @@ export function useSmartAccount() {
3939
) as Hex;
4040

4141
const publicClient = createPublicClient({
42-
chain: arbitrumSepolia,
42+
chain: baseSepolia,
4343
transport: http(),
4444
cacheTime: 60_000,
4545
batch: {
@@ -52,30 +52,28 @@ export function useSmartAccount() {
5252
if (localStorageAddress) {
5353
smartAccount = await createSafeSmartAccount({
5454
apiKey,
55-
chain: arbitrumSepolia,
55+
chain: baseSepolia,
5656
publicClient,
5757
smartAccountAddress: localStorageAddress,
58-
entryPoint: ENTRYPOINT_ADDRESS_V07,
5958
});
6059
} else {
6160
smartAccount = await createSafeSmartAccount({
6261
apiKey,
63-
chain: arbitrumSepolia,
62+
chain: baseSepolia,
6463
publicClient,
65-
entryPoint: ENTRYPOINT_ADDRESS_V07,
6664
});
6765
window.localStorage.setItem("walletAddress", smartAccount.address);
6866
}
6967

7068
const paymasterClient = await createComethPaymasterClient({
7169
transport: http(paymasterUrl),
72-
chain: arbitrumSepolia,
70+
chain: baseSepolia,
7371
publicClient,
7472
});
7573

7674
const smartAccountClient = createSmartAccountClient({
7775
account: smartAccount,
78-
chain: arbitrumSepolia,
76+
chain: baseSepolia,
7977
bundlerTransport: http(bundlerUrl, {
8078
retryCount: 5,
8179
retryDelay: 1000,

packages/react/src/actions/createSmartAccount.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,13 @@ export async function createSmartAccount(
6161
estimateFeesPerGas: async () => {
6262
return await paymasterClient.getUserOperationGasPrice();
6363
},
64-
},
65-
publicClient,
64+
}
6665
}) as ContextComethSmartAccountClient;
6766
} else {
6867
client = createSmartAccountClient({
6968
account: account as ComethSafeSmartAccount,
7069
chain,
71-
bundlerTransport: http(bundlerUrl),
72-
publicClient,
70+
bundlerTransport: http(bundlerUrl)
7371
}) as ContextComethSmartAccountClient;
7472
}
7573

0 commit comments

Comments
 (0)