@@ -6,7 +6,7 @@ import { toChecksumAddress } from '@ethereumjs/util'
6
6
import { SmartAccount } from "../types"
7
7
import "viem/window"
8
8
import { custom , createWalletClient , createPublicClient , http } from "viem"
9
- import { sepolia } from "viem/chains"
9
+ import * as chains from "viem/chains"
10
10
import { entryPoint07Address } from "viem/account-abstraction"
11
11
const { createSmartAccountClient } = require ( "permissionless" ) /* eslint-disable-line @typescript-eslint/no-var-requires */
12
12
const { toSafeSmartAccount } = require ( "permissionless/accounts" ) /* eslint-disable-line @typescript-eslint/no-var-requires */
@@ -102,25 +102,60 @@ export const createNewBlockchainAccount = async (plugin: RunTab, dispatch: React
102
102
)
103
103
}
104
104
105
+ const createSafeSmartAccount = async ( safeAccount , toAddress , usePaymaster , chainObj ) => {
106
+ const PIMLICO_API_KEY = ''
107
+ const chainName = chainObj . name
108
+ const BUNDLER_URL = `https://api.pimlico.io/v2/${ chainName } /rpc?apikey=${ PIMLICO_API_KEY } `
109
+ const paymasterClient = createPimlicoClient ( {
110
+ transport : http ( BUNDLER_URL ) ,
111
+ entryPoint : {
112
+ address : entryPoint07Address ,
113
+ version : "0.7" ,
114
+ } ,
115
+ } )
116
+
117
+ console . log ( 'paymasterClient--->' , paymasterClient ) // api key is shown
118
+
119
+ const saClient = createSmartAccountClient ( {
120
+ account : safeAccount ,
121
+ chainObj,
122
+ paymaster : paymasterClient ,
123
+ bundlerTransport : http ( BUNDLER_URL ) ,
124
+ userOperation : {
125
+ estimateFeesPerGas : async ( ) => ( await paymasterClient . getUserOperationGasPrice ( ) ) . fast ,
126
+ }
127
+ } )
128
+ console . log ( 'saClient--->' , saClient ) // api key is shown
129
+
130
+ // Make a dummy tx to force smart account deployment
131
+ const useropHash = await saClient . sendUserOperation ( {
132
+ calls : [ {
133
+ to : toAddress ,
134
+ value : 0
135
+ } ]
136
+ } )
137
+ await saClient . waitForUserOperationReceipt ( { hash : useropHash } )
138
+ }
139
+
105
140
export const createSmartAccount = async ( plugin : RunTab , dispatch : React . Dispatch < any > ) => {
106
141
const localStorageKey = 'smartAccounts'
107
142
const PUBLIC_NODE_URL = "https://go.getblock.io/ee42d0a88f314707be11dd799b122cb9"
108
- const PIMLICO_API_KEY = ''
109
- const BUNDLER_URL = `https://api.pimlico.io/v2/sepolia/rpc?apikey=${ PIMLICO_API_KEY } `
110
143
const safeAddresses : string [ ] = Object . keys ( plugin . REACT_API . smartAccounts )
144
+ const network = 'sepolia'
145
+ const chain = chains [ network ]
111
146
let salt
112
147
113
148
// @ts -ignore
114
149
const [ account ] = await window . ethereum ! . request ( { method : 'eth_requestAccounts' } )
115
150
116
151
const walletClient = createWalletClient ( {
117
152
account,
118
- chain : sepolia ,
153
+ chain,
119
154
transport : custom ( window . ethereum ! ) ,
120
155
} )
121
156
122
157
const publicClient = createPublicClient ( {
123
- chain : sepolia ,
158
+ chain,
124
159
transport : http ( PUBLIC_NODE_URL ) // choose any provider here
125
160
} )
126
161
@@ -141,33 +176,8 @@ export const createSmartAccount = async (plugin: RunTab, dispatch: React.Dispatc
141
176
saltNonce : salt ,
142
177
version : "1.4.1"
143
178
} )
144
-
145
- const paymasterClient = createPimlicoClient ( {
146
- transport : http ( BUNDLER_URL ) ,
147
- entryPoint : {
148
- address : entryPoint07Address ,
149
- version : "0.7" ,
150
- } ,
151
- } )
152
-
153
- const saClient = createSmartAccountClient ( {
154
- account : safeAccount ,
155
- sepolia,
156
- paymaster : paymasterClient ,
157
- bundlerTransport : http ( BUNDLER_URL ) ,
158
- userOperation : {
159
- estimateFeesPerGas : async ( ) => ( await paymasterClient . getUserOperationGasPrice ( ) ) . fast ,
160
- }
161
- } )
162
- // Make a dummy tx to force smart account deployment
163
- const useropHash = await saClient . sendUserOperation ( {
164
- calls : [ {
165
- to : "0xAFdAC33F6F134D46bAbE74d9125F3bf8e8AB3a44" ,
166
- value : 0
167
- } ]
168
- } )
169
- await saClient . waitForUserOperationReceipt ( { hash : useropHash } )
170
-
179
+ await createSafeSmartAccount ( safeAccount , '0xAFdAC33F6F134D46bAbE74d9125F3bf8e8AB3a44' , true , chain )
180
+ // TO verify creation, check if there is a contract code at this address
171
181
const safeAddress = safeAccount . address
172
182
173
183
const sAccount : SmartAccount = {
0 commit comments