Skip to content

Commit bc16b72

Browse files
committed
CSM endpoint
1 parent 5898bc1 commit bc16b72

File tree

2 files changed

+59
-49
lines changed

2 files changed

+59
-49
lines changed

Diff for: libs/remix-ui/run-tab/src/lib/actions/account.ts

+42-32
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { toChecksumAddress } from '@ethereumjs/util'
66
import { SmartAccount } from "../types"
77
import "viem/window"
88
import { custom, createWalletClient, createPublicClient, http } from "viem"
9-
import { sepolia } from "viem/chains"
9+
import * as chains from "viem/chains"
1010
import { entryPoint07Address } from "viem/account-abstraction"
1111
const { createSmartAccountClient } = require("permissionless") /* eslint-disable-line @typescript-eslint/no-var-requires */
1212
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
102102
)
103103
}
104104

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+
105140
export const createSmartAccount = async (plugin: RunTab, dispatch: React.Dispatch<any>) => {
106141
const localStorageKey = 'smartAccounts'
107142
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}`
110143
const safeAddresses: string[] = Object.keys(plugin.REACT_API.smartAccounts)
144+
const network = 'sepolia'
145+
const chain = chains[network]
111146
let salt
112147

113148
// @ts-ignore
114149
const [account] = await window.ethereum!.request({ method: 'eth_requestAccounts' })
115150

116151
const walletClient = createWalletClient({
117152
account,
118-
chain: sepolia,
153+
chain,
119154
transport: custom(window.ethereum!),
120155
})
121156

122157
const publicClient = createPublicClient({
123-
chain: sepolia,
158+
chain,
124159
transport: http(PUBLIC_NODE_URL) // choose any provider here
125160
})
126161

@@ -141,33 +176,8 @@ export const createSmartAccount = async (plugin: RunTab, dispatch: React.Dispatc
141176
saltNonce: salt,
142177
version: "1.4.1"
143178
})
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
171181
const safeAddress = safeAccount.address
172182

173183
const sAccount: SmartAccount = {

Diff for: libs/remix-ui/run-tab/src/lib/components/account.tsx

+17-17
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@ export function AccountUI(props: AccountProps) {
3131
}, [accounts, selectedAccount])
3232

3333
// Uncomment this when we want to show 'Create Smart Account' button
34-
// useEffect(() => {
35-
// if (smartAccounts.length > 0 && networkName.includes('Sepolia')) {
36-
// if(smartAccounts.includes(selectedAccount)) {
37-
// setSmartAccountSelected(true)
38-
// setEnableCSM(false)
39-
// ownerEOA.current = props.runTabPlugin.REACT_API.smartAccounts[selectedAccount].ownerEOA
40-
// }
41-
// else {
42-
// setSmartAccountSelected(false)
43-
// setEnableCSM(true)
44-
// ownerEOA.current = null
45-
// }
46-
// } else {
47-
// setEnableCSM(false)
48-
// setSmartAccountSelected(false)
49-
// }
50-
// }, [selectedAccount])
34+
useEffect(() => {
35+
if (smartAccounts.length > 0 && networkName.includes('Sepolia')) {
36+
if(smartAccounts.includes(selectedAccount)) {
37+
setSmartAccountSelected(true)
38+
setEnableCSM(false)
39+
ownerEOA.current = props.runTabPlugin.REACT_API.smartAccounts[selectedAccount].ownerEOA
40+
}
41+
else {
42+
setSmartAccountSelected(false)
43+
setEnableCSM(true)
44+
ownerEOA.current = null
45+
}
46+
} else {
47+
setEnableCSM(false)
48+
setSmartAccountSelected(false)
49+
}
50+
}, [selectedAccount])
5151

5252
useEffect(() => {
5353
props.setAccount('')

0 commit comments

Comments
 (0)