Created
April 26, 2024 03:24
-
-
Save denniswon/27a928775468564ecd3f872f48ebedb6 to your computer and use it in GitHub Desktop.
split rpc for bundler, paymater and public rpc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const client = createBundlerClient({ | |
chain, | |
transport: (opts) => { | |
const bundlerRpc = http(`${rpcUrl}/${API_KEY_STAGING}`)(opts); | |
const publicRpc = http(`${chain.rpcUrls.alchemy.http[0]}/${API_KEY}`)( | |
opts | |
); | |
return custom({ | |
request: async (args) => { | |
const bundlerMethods = new Set([ | |
"eth_sendUserOperation", | |
"eth_estimateUserOperationGas", | |
"eth_getUserOperationReceipt", | |
"eth_getUserOperationByHash", | |
"eth_supportedEntryPoints", | |
]); | |
if (bundlerMethods.has(args.method)) { | |
return bundlerRpc.request(args); | |
} else { | |
return publicRpc.request(args); | |
} | |
}, | |
})(opts); | |
}, | |
}); | |
return createSmartAccountClientFromExisting({ | |
client, | |
account: await createSimpleSmartAccount({ | |
chain, | |
signer, | |
entryPoint: getEntryPoint(chain, { version: "0.7.0" }), | |
transport: custom(client), | |
accountAddress, | |
}), | |
feeEstimator: async (struct) => ({ | |
...struct, | |
maxFeePerGas: 1_000_000_000n, | |
maxPriorityFeePerGas: 500_000_000n, | |
}), | |
opts: { feeOptions }, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment