44 ZKsync SSO Demo
55 </h1 >
66 <button
7- class =" bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
8- @click =" address ? disconnectWallet() : connectWallet()"
7+ class =" bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded mr-4 "
8+ @click =" address ? disconnectWallet() : connectWallet(false )"
99 >
1010 {{ address ? "Disconnect" : "Connect" }}
1111 </button >
12+ <button
13+ v-if =" !address"
14+ class =" bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
15+ @click =" address ? disconnectWallet() : connectWallet(true)"
16+ >
17+ Connect w/ Session
18+ </button >
1219 <div
1320 v-if =" address"
1421 class =" mt-4"
2330 </div >
2431 <button
2532 v-if =" address"
26- class =" bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded mt-3"
33+ class =" bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded mt-3 mr-4 disabled:bg-slate-300 "
2734 :disabled =" isSendingEth"
28- @click =" sendTokens()"
35+ @click =" sendTokens(false )"
2936 >
3037 Send 0.1 ETH
3138 </button >
39+ <button
40+ v-if =" address"
41+ class =" bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded mt-3 disabled:bg-slate-300"
42+ :disabled =" isSendingEth"
43+ @click =" sendTokens(true)"
44+ >
45+ Send 0.1 ETH w/ Paymaster
46+ </button >
3247
3348 <div
3449 v-if =" errorMessage"
@@ -45,11 +60,13 @@ import { zksyncSsoConnector } from "zksync-sso/connector";
4560import { zksyncInMemoryNode } from " @wagmi/core/chains" ;
4661import { createWalletClient , http , parseEther , type Address } from " viem" ;
4762import { privateKeyToAccount } from " viem/accounts" ;
63+ import { getGeneralPaymasterInput } from " viem/zksync" ;
64+ import PaymasterContract from " ../forge-output.json" ;
4865
4966const chain = zksyncInMemoryNode ;
5067
5168const testTransferTarget = " 0x55bE1B079b53962746B2e86d12f158a41DF294A6" ;
52- const zksyncConnector = zksyncSsoConnector ({
69+ const zksyncConnectorWithSession = zksyncSsoConnector ({
5370 authServerUrl: " http://localhost:3002/confirm" ,
5471 session: {
5572 feeLimit: parseEther (" 0.1" ),
@@ -61,6 +78,9 @@ const zksyncConnector = zksyncSsoConnector({
6178 ],
6279 },
6380});
81+ const zksyncConnector = zksyncSsoConnector ({
82+ authServerUrl: " http://localhost:3002/confirm" ,
83+ });
6484const wagmiConfig = createConfig ({
6585 chains: [chain ],
6686 connectors: [zksyncConnector ],
@@ -84,10 +104,20 @@ const fundAccount = async () => {
84104 transport: http (),
85105 });
86106
87- await richClient .sendTransaction ({
107+ let transactionHash = await richClient .sendTransaction ({
88108 to: address .value ,
89109 value: parseEther (" 1" ),
90110 });
111+ // FIXME: When not using sessions, sendTransaction returns a map and not a string
112+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
113+ if ((transactionHash as any ).value !== undefined ) {
114+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
115+ transactionHash = (transactionHash as any ).value ;
116+ }
117+
118+ await waitForTransactionReceipt (wagmiConfig , {
119+ hash: transactionHash ,
120+ });
91121};
92122
93123watchAccount (wagmiConfig , {
@@ -118,11 +148,11 @@ watch(address, async () => {
118148 balance .value = currentBalance ;
119149}, { immediate: true });
120150
121- const connectWallet = async () => {
151+ const connectWallet = async (useSession : boolean ) => {
122152 try {
123153 errorMessage .value = " " ;
124154 connect (wagmiConfig , {
125- connector: zksyncConnector ,
155+ connector: useSession ? zksyncConnectorWithSession : zksyncConnector ,
126156 chainId: chain .id ,
127157 });
128158 } catch (error ) {
@@ -133,25 +163,45 @@ const connectWallet = async () => {
133163};
134164
135165const disconnectWallet = async () => {
166+ errorMessage .value = " " ;
136167 await disconnect (wagmiConfig );
137168};
138169
139- const sendTokens = async () => {
170+ const sendTokens = async (usePaymaster : boolean ) => {
140171 if (! address .value ) return ;
141172
142173 errorMessage .value = " " ;
143174 isSendingEth .value = true ;
144175 try {
145- const transactionHash = await sendTransaction (wagmiConfig , {
146- to: testTransferTarget ,
147- value: parseEther (" 0.1" ),
148- });
176+ let transactionHash;
149177
178+ if (usePaymaster ) {
179+ transactionHash = await sendTransaction (wagmiConfig , {
180+ to: testTransferTarget ,
181+ value: parseEther (" 0.1" ),
182+ paymaster: PaymasterContract .deployedTo as ` 0x${string } ` ,
183+ paymasterInput: getGeneralPaymasterInput ({ innerInput: " 0x" }),
184+ });
185+ } else {
186+ transactionHash = await sendTransaction (wagmiConfig , {
187+ to: testTransferTarget ,
188+ value: parseEther (" 0.1" ),
189+ });
190+ }
191+
192+ // FIXME: When not using sessions, sendTransaction returns a map and not a string
193+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
194+ if ((transactionHash as any ).value !== undefined ) {
195+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
196+ transactionHash = (transactionHash as any ).value ;
197+ }
198+
199+ const receipt = await waitForTransactionReceipt (wagmiConfig , {
200+ hash: transactionHash ,
201+ });
150202 balance .value = await getBalance (wagmiConfig , {
151203 address: address .value ,
152204 });
153-
154- const receipt = await waitForTransactionReceipt (wagmiConfig , { hash: transactionHash });
155205 if (receipt .status === " reverted" ) throw new Error (" Transaction reverted" );
156206 } catch (error ) {
157207 // eslint-disable-next-line no-console
@@ -162,6 +212,10 @@ const sendTokens = async () => {
162212 // eslint-disable-next-line @typescript-eslint/no-explicit-any
163213 transactionFailureDetails = (error as any ).cause ?.cause ?.data ?.originalError ?.cause ?.details ;
164214 }
215+ if (! transactionFailureDetails ) {
216+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
217+ transactionFailureDetails = (error as any ).cause ?.details ;
218+ }
165219
166220 if (transactionFailureDetails ) {
167221 errorMessage .value = transactionFailureDetails ;
0 commit comments