@@ -61,19 +61,6 @@ export async function replaceMnemonic(mnemonicOrPrivateKey: string) {
6161export async function calculateEip155Gas ( transaction : any , chainId : string ) {
6262 console . log ( 'calculateEip155Gas:' , chainId ) ;
6363 const chainData = PresetsUtil . getChainData ( parseChainId ( chainId ) ) ;
64- console . log ( 'chainData:' ) ;
65- // Define the sender (from) and receiver (to) addresses
66- const from = transaction . from ;
67- const to = transaction . to ; // Could be a contract address
68- const data = transaction . data ; // Some contract interaction data
69-
70- // Prepare the transaction object
71- const tx = {
72- from : from ,
73- to : to ,
74- data : data ,
75- } ;
76-
7764 let provider = new ethers . providers . JsonRpcProvider ( chainData . rpcUrl ) ;
7865
7966 // Fetch the latest block to get the base fee
@@ -90,56 +77,26 @@ export async function calculateEip155Gas(transaction: any, chainId: string) {
9077 // Calculate the max fee per gas (base fee + priority fee)
9178 const maxFeePerGas = baseFee ! . add ( maxPriorityFeePerGas ) ;
9279
93- try {
94- // use this node to estimate gas as it doesn't reject when the amount is greater than the balance
95- // very useful for chain abstraction
96- provider = new ethers . providers . JsonRpcProvider (
97- 'https://endpoints.omniatech.io/v1/arbitrum/one/public' ,
98- ) ;
99-
100- // Estimate the gas limit for this transaction based on its size and complexity
101- const gasLimit = await provider . estimateGas ( tx ) ;
102-
103- // Log the details of the gas fees
104- console . log (
105- 'Base Fee:' ,
106- ethers . utils . formatUnits ( baseFee ! , 'gwei' ) ,
107- 'Gwei' ,
108- ) ;
109- console . log (
110- 'Max Priority Fee:' ,
111- ethers . utils . formatUnits ( maxPriorityFeePerGas , 'gwei' ) ,
112- 'Gwei' ,
113- ) ;
114- console . log (
115- 'Max Fee per Gas:' ,
116- ethers . utils . formatUnits ( maxFeePerGas , 'gwei' ) ,
117- 'Gwei' ,
118- ) ;
119- console . log ( 'Estimated Gas Limit:' , gasLimit . toString ( ) ) ;
120-
121- // The total gas cost (just as an example, no sign and send in this code)
122- const estimatedGasCost = gasLimit . mul ( maxFeePerGas ) ;
123- console . log ( 'Estimated Gas Cost (Wei):' , estimatedGasCost . toString ( ) ) ;
124-
125- return {
126- maxFeePerGas : ethers . utils . formatUnits ( maxFeePerGas , 'wei' ) ,
127- maxPriorityFeePerGas : ethers . utils . formatUnits (
128- maxPriorityFeePerGas ,
129- 'wei' ,
130- ) ,
131- gasLimit,
132- totalGas : ethers . utils . formatUnits ( estimatedGasCost , 'ether' ) ,
133- } ;
134- } catch ( error ) {
135- console . error ( 'Error fetching gas fees:' , error ) ;
136- return {
137- gasLimit : { hex : '0x05b6a8' , type : 'BigNumber' } ,
138- maxFeePerGas : maxFeePerGas ,
139- maxPriorityFeePerGas : '1100000' ,
140- totalGas : '0.00000020607740523' ,
141- } ;
142- }
80+ const gasLimit = ethers . BigNumber . from ( 0x05b6a8 ) ;
81+ // Log the details of the gas fees
82+ console . log ( 'Base Fee:' , ethers . utils . formatUnits ( baseFee ! , 'gwei' ) , 'Gwei' ) ;
83+ console . log (
84+ 'Max Priority Fee:' ,
85+ ethers . utils . formatUnits ( maxPriorityFeePerGas , 'gwei' ) ,
86+ 'Gwei' ,
87+ ) ;
88+ console . log (
89+ 'Max Fee per Gas:' ,
90+ ethers . utils . formatUnits ( maxFeePerGas , 'gwei' ) ,
91+ 'Gwei' ,
92+ ) ;
93+ console . log ( 'Estimated Gas Limit:' , gasLimit . toString ( ) ) ;
94+
95+ return {
96+ maxFeePerGas : ethers . utils . formatUnits ( maxFeePerGas , 'wei' ) ,
97+ maxPriorityFeePerGas : ethers . utils . formatUnits ( maxPriorityFeePerGas , 'wei' ) ,
98+ gasLimit : ethers . utils . formatUnits ( gasLimit , 'wei' ) ,
99+ } ;
143100}
144101
145102const fetchGasPrice = async ( chainId : string ) => {
@@ -153,16 +110,6 @@ const fetchGasPrice = async (chainId: string) => {
153110 return data ?. data ;
154111} ;
155112
156- export async function getTransactionGas ( tx : any , chainId : string ) {
157- const chainData = PresetsUtil . getChainData ( parseChainId ( chainId ) ) ;
158- const provider = new ethers . providers . JsonRpcProvider ( chainData . rpcUrl ) ;
159- const feeData = await provider . getFeeData ( ) ;
160- return {
161- maxFeePerGas : feeData . maxFeePerGas ,
162- maxPriorityFeePerGas : feeData . maxPriorityFeePerGas ,
163- } ;
164- }
165-
166113export async function calculateGasLimit ( tx : any , chainId : string ) {
167114 const chainData = PresetsUtil . getChainData ( parseChainId ( chainId ) ) ;
168115 const provider = new ethers . providers . JsonRpcProvider ( chainData . rpcUrl ) ;
0 commit comments