From 8a4b06b46e3a00ec583db585564b7c2d230ff973 Mon Sep 17 00:00:00 2001 From: Mikhail <16622558+mmv08@users.noreply.github.com> Date: Tue, 16 Jul 2024 12:55:47 +0200 Subject: [PATCH] Alchemy wip --- examples/4337-gas-metering/alchemy/alchemy.ts | 3 ++- examples/4337-gas-metering/utils/userOps.ts | 20 +++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/examples/4337-gas-metering/alchemy/alchemy.ts b/examples/4337-gas-metering/alchemy/alchemy.ts index 7cc259567..86616eafd 100644 --- a/examples/4337-gas-metering/alchemy/alchemy.ts +++ b/examples/4337-gas-metering/alchemy/alchemy.ts @@ -215,7 +215,7 @@ if (usePaymaster) { console.log('\nTransferred required ETH for the transaction.') } } - +console.dir(sponsoredUserOperation, { depth: null }) sponsoredUserOperation.signature = await signUserOperation( sponsoredUserOperation, signer, @@ -225,4 +225,5 @@ sponsoredUserOperation.signature = await signUserOperation( ) console.log('\nSigned Real Data including Paymaster Data Created by Alchemy.\n') + await submitUserOperationAlchemy(entryPointAddress, sponsoredUserOperation, chain, apiKey) diff --git a/examples/4337-gas-metering/utils/userOps.ts b/examples/4337-gas-metering/utils/userOps.ts index 08589ebbf..b7506016c 100644 --- a/examples/4337-gas-metering/utils/userOps.ts +++ b/examples/4337-gas-metering/utils/userOps.ts @@ -229,7 +229,7 @@ export const getGasValuesFromAlchemy = async ( { sender: sponsoredUserOperation.sender, nonce: '0x' + sponsoredUserOperation.nonce.toString(16), - initCode: sponsoredUserOperation.initCode, + initCode: getInitCode(sponsoredUserOperation), callData: sponsoredUserOperation.callData, callGasLimit: '0x1', verificationGasLimit: '0x1', @@ -237,20 +237,24 @@ export const getGasValuesFromAlchemy = async ( maxFeePerGas: sponsoredUserOperation.maxFeePerGas.toString(16), maxPriorityFeePerGas: sponsoredUserOperation.maxPriorityFeePerGas.toString(16), signature: sponsoredUserOperation.signature, - paymasterAndData: '0x', + paymasterAndData: getPaymasterAndData(sponsoredUserOperation), }, entryPointAddress, ], }), } - let responseValues - await fetch('https://eth-' + chain + '.g.alchemy.com/v2/' + apiKey, gasOptions) + const responseValues = await fetch('https://eth-' + chain + '.g.alchemy.com/v2/' + apiKey, gasOptions) .then((response) => response.json()) - .then((response) => (responseValues = response)) + .then((json) => { + if (json.error && 'message' in json.error) { + throw new Error(json.error.message) + } + return json + }) .catch((err) => console.error(err)) console.log('\nReceived Gas Data from Alchemy.') - + console.log(responseValues) let rvGas if (responseValues && responseValues['result']) { rvGas = responseValues['result'] as gasData @@ -276,7 +280,7 @@ export const submitUserOperationAlchemy = async ( { sender: sponsoredUserOperation.sender, nonce: '0x' + sponsoredUserOperation.nonce.toString(16), - initCode: sponsoredUserOperation.initCode, + initCode: getInitCode(sponsoredUserOperation), callData: sponsoredUserOperation.callData, callGasLimit: sponsoredUserOperation.callGasLimit.toString(16), verificationGasLimit: sponsoredUserOperation.verificationGasLimit.toString(16), @@ -284,7 +288,7 @@ export const submitUserOperationAlchemy = async ( maxFeePerGas: sponsoredUserOperation.maxFeePerGas.toString(16), maxPriorityFeePerGas: sponsoredUserOperation.maxPriorityFeePerGas.toString(16), signature: sponsoredUserOperation.signature, - paymasterAndData: sponsoredUserOperation.paymasterAndData, + paymasterAndData: getPaymasterAndData(sponsoredUserOperation), }, entryPointAddress, ],