starknet-react icon indicating copy to clipboard operation
starknet-react copied to clipboard

Add support for estimate fees and simulate transactions

Open VenkatTeja opened this issue 1 year ago • 3 comments

As described in title, it would be good to have support for these two features. We could propose a standard and take help of wallets to do necessary integrations.

Reason for estimate fees: DApps will be able to show precise fee to users on their UI's itself

Reason for simulate: Dapps will be able to precisely use info on tokens in and out to give users easy clarity on what they would receive finally. Usually, this is an easy thing for simple contracts, but for projects like Hashstack.finance which involve integrations with different DeFi apps for swaps, liquidity provisions, staking etc, being able to write logic to estimate tokens output can itself be complex math. Given that the RPC supports simulation, exposing it could be easier and may even help others?

VenkatTeja avatar Mar 11 '24 13:03 VenkatTeja

I haven't checked the project code in detail, but if project contributors think this can be implemented, I can try working on this.

VenkatTeja avatar Mar 11 '24 13:03 VenkatTeja

Hello, yes I think it would be very useful. My understanding is that we need two steps:

  • Create a new hook (useEstimateFees, usually I use the rpc method name) to estimate the fees.
  • Update the useContractWrite hook to accept the fee estimation from the previous hook.

fracek avatar Mar 14 '24 14:03 fracek

@fracek will try to complete this and raise a PR.

VenkatTeja avatar Mar 17 '24 07:03 VenkatTeja