Skip to content

Commit

Permalink
Alchemy wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mmv08 committed Jul 16, 2024
1 parent d661ff9 commit 8a4b06b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion examples/4337-gas-metering/alchemy/alchemy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
20 changes: 12 additions & 8 deletions examples/4337-gas-metering/utils/userOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,28 +229,32 @@ 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',
preVerificationGas: '0x1',
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
Expand All @@ -276,15 +280,15 @@ 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),
preVerificationGas: sponsoredUserOperation.preVerificationGas.toString(16),
maxFeePerGas: sponsoredUserOperation.maxFeePerGas.toString(16),
maxPriorityFeePerGas: sponsoredUserOperation.maxPriorityFeePerGas.toString(16),
signature: sponsoredUserOperation.signature,
paymasterAndData: sponsoredUserOperation.paymasterAndData,
paymasterAndData: getPaymasterAndData(sponsoredUserOperation),
},
entryPointAddress,
],
Expand Down

0 comments on commit 8a4b06b

Please sign in to comment.