@@ -12,9 +12,11 @@ import {
12
12
THIRDWEB_STORAGE_DOMAIN ,
13
13
} from "constants/urls" ;
14
14
import { createThirdwebClient } from "thirdweb" ;
15
+ import { getChainMetadata } from "thirdweb/chains" ;
15
16
import { populateEip712Transaction } from "thirdweb/transaction" ;
16
17
import {
17
18
getTransactionDecorator ,
19
+ isZkSyncChain ,
18
20
setThirdwebDomains ,
19
21
setTransactionDecorator ,
20
22
} from "thirdweb/utils" ;
@@ -37,32 +39,43 @@ export function getThirdwebClient(jwt?: string) {
37
39
38
40
if ( ! getTransactionDecorator ( ) ) {
39
41
setTransactionDecorator ( async ( { account, transaction } ) => {
40
- // special override for sophon testnet (zk chain)
41
- // sophon only allows transactions through their paymaster
42
- // so always use eip712 tx + paymaster
43
- if ( transaction . chain . id === 531050104 ) {
44
- const serializedTx = await populateEip712Transaction ( {
45
- transaction,
46
- account,
47
- } ) ;
48
- const pmData = await getZkPaymasterData ( {
49
- options : {
50
- client : transaction . client ,
51
- chain : transaction . chain ,
52
- } ,
53
- transaction : serializedTx ,
54
- } ) ;
55
- return {
56
- account,
57
- transaction : {
58
- ...transaction ,
59
- eip712 : {
60
- ...transaction . eip712 ,
61
- paymaster : pmData . paymaster ,
62
- paymasterInput : pmData . paymasterInput ,
42
+ // use paymaster for zk chains on testnets
43
+ const chainMeta = await getChainMetadata ( transaction . chain ) ;
44
+ if ( chainMeta . testnet ) {
45
+ const isZkChain = await isZkSyncChain ( transaction . chain ) ;
46
+ if ( isZkChain ) {
47
+ const serializedTx = await populateEip712Transaction ( {
48
+ transaction,
49
+ account,
50
+ } ) ;
51
+ const pmData = await getZkPaymasterData ( {
52
+ options : {
53
+ client : transaction . client ,
54
+ chain : transaction . chain ,
63
55
} ,
64
- } ,
65
- } ;
56
+ transaction : serializedTx ,
57
+ } ) . catch ( ( e ) => {
58
+ console . warn (
59
+ "No zk paymaster data available on chain " ,
60
+ transaction . chain . id ,
61
+ e ,
62
+ ) ;
63
+ return undefined ;
64
+ } ) ;
65
+ return {
66
+ account,
67
+ transaction : {
68
+ ...transaction ,
69
+ eip712 : pmData
70
+ ? {
71
+ ...transaction . eip712 ,
72
+ paymaster : pmData . paymaster ,
73
+ paymasterInput : pmData . paymasterInput ,
74
+ }
75
+ : transaction . eip712 ,
76
+ } ,
77
+ } ;
78
+ }
66
79
}
67
80
return { account, transaction } ;
68
81
} ) ;
0 commit comments