Ethers.js how to calculate gas used in transaction
January 11th, 2023

Way to calculate how much gas was used in trx is to destruct the transaction object as below and multiply gas used with gas price.

            const transactionResponse = await fundMe.withdraw();
            const transactionReceipt = await transactionResponse.wait(1);
            const { gasUsed, effectiveGasPrice } = transactionReceipt;
            const gasCost = gasUsed.mul(effectiveGasPrice); 
Subscribe to N00b21337
Receive the latest updates directly to your inbox.
Nft graphic
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.
More from N00b21337

Skeleton

Skeleton

Skeleton