Prime SDK examples
Show gas fee in fiat
With account abstraction we want to give users who are new to blockchain as simple a user experience as possible.
Showing the gas fee in USD rather than the native token will make it a lot easier to understand for newer users, and we can do this in a couple of simple steps.
First we start by estimating the current batch of UserOps. This will be the units of gas used.
Then we want to get the gas in wei for this batch.
And multiply this by the current gas fees on the network.
Next fix the formatting using the formatEther from ethers.
Then get the current price of the native token to the network.
Finally, multiply the current token price by the gas in the token to get the gas price in USD for this transaction.