Skip to content

Commit

Permalink
useEstiamteFees hook docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ugur-eren committed Mar 30, 2024
1 parent e7f4920 commit be3af86
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions website/content/hooks/query/useEstimateFees.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: useEstimateFees
priority: 194
hookType: query
---

Perform fee estimation for smart contract calls. Estimation then later can be used to specify the `maxFee` for the actual contract call.

## Usage

```ts
import { useAccount, useContract, useEstimateFees } from "@starknet-react/core";

export default function Component() {
const { address } = useAccount();

const { contract } = useContract({
abi: erc20ABI,
address: chain.nativeCurrency.address,
});

const calls = useMemo(() => {
if (!address || !contract) return [];
return contract.populateTransaction["transfer"]!(address, { low: 1, high: 0 });
}, [contract, address]);

const { data, isError, isLoading, error } = useEstimateFees({
calls,
watch: true,
});

if (isLoading) return <div>Loading ...</div>;
if (isError || !data) return <div>{error?.message}</div>;

return <div>Suggested Max Fee: {data.suggestedMaxFee}</div>;
}
```

## Options

- **calls**`: string`
- The contract calls to estimate fees for.
- **options**`: string`
- Estimation options.
- EstimateFeeDetails from starknet.js
- **watch?**`: boolean`
- If true, refresh data at every block.

## Returns

- **data?**`: EstimateFeeResponse`
- Estimated fees for the contract calls.
- EstimateFeeResponse from starknet.js

0 comments on commit be3af86

Please sign in to comment.