# \`.get()\` method calls \`dryRun\` and \`estimateGasPrice\`

**URL:** <https://forum.fuel.network/t/get-method-calls-dryrun-and-estimategasprice/6651>\
**Category:** TypeScript SDK\
**Created:** [September 21, 2024, 9:15am UTC](https://forum.fuel.network/t/get-method-calls-dryrun-and-estimategasprice/6651 "2024-09-21T09:15:28Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![martines3000](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/martines3000/32/3523_2.png) [@martines3000](https://forum.fuel.network/u/martines3000)\
**Post date:** [September 21, 2024, 9:15am UTC](https://forum.fuel.network/t/get-method-calls-dryrun-and-estimategasprice/6651/1 "2024-09-21T09:15:28Z")

</div>

Version used:

- `@fuel-ts/contract: "^0.94.6"`
- `@fuels/connectors": "^0.27.1"`
- `@fuels/react": "^0.27.1"`
- `fuels: "^0.94.6"`

I generated the smart contract types using `fuels typegen`.

Smart contract reads being executed as follow:

```ts
 const marketContract = new Market(
    marketAddress,
    provider
  );

  const { value: marketConfiguration } = await marketContract.functions
    .get_market_configuration()
    .get();

```

The `.get()` method executes `dryRun` and `estimateGasPrice` as seen in the following screenshot:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/5/53f9375f6cb181d04f8659689f2a3b48e3330d07.png)

This, with the additional problem of requests not being deduplicated for `getNodeInfo` and `getChainInfo`, causes a large number of unnecessary requests being made. The initial load of our dapp does 49 requests to the testnet node. We verified that there are not duplicate requests being fired from our own hooks, because of re-renders, etc.

---

<div class="post-metadata">

**Author:** ![p.s](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/p.s/32/2491_2.png) [@p.s](https://forum.fuel.network/u/p.s)\
**Post date:** [September 23, 2024, 11:24am UTC](https://forum.fuel.network/t/get-method-calls-dryrun-and-estimategasprice/6651/2 "2024-09-23T11:24:32Z")

</div>

> [@martines3000](#):
>
> This, with the additional problem of requests not being deduplicated for `getNodeInfo` and `getChainInfo`, causes a large number of unnecessary requests being made. The initial load of our dapp does 49 requests to the testnet node. We verified that there are not duplicate requests being fired from our own hooks, because of re-renders, etc.

Hey @martines3000 👋

Don’t suppose you have a minimal reproduction of this issue?

---

<div class="post-metadata">

**Author:** ![martines3000](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/martines3000/32/3523_2.png) [@martines3000](https://forum.fuel.network/u/martines3000)\
**Post date:** [September 23, 2024, 11:34am UTC](https://forum.fuel.network/t/get-method-calls-dryrun-and-estimategasprice/6651/3 "2024-09-23T11:34:39Z")

</div>

No, the repository is still private, but I can add you if you share your GitHub username.

---

<div class="post-metadata">

**Author:** ![p.s](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/p.s/32/2491_2.png) [@p.s](https://forum.fuel.network/u/p.s)\
**Post date:** [September 23, 2024, 11:36am UTC](https://forum.fuel.network/t/get-method-calls-dryrun-and-estimategasprice/6651/4 "2024-09-23T11:36:52Z")

</div>

Github: `petertonysmith94`

---

<div class="post-metadata">

**Author:** ![Torres-ssf](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/torres-ssf/32/1380_2.png) [@Torres-ssf](https://forum.fuel.network/u/Torres-ssf)\
**Post date:** [September 23, 2024, 12:56pm UTC](https://forum.fuel.network/t/get-method-calls-dryrun-and-estimategasprice/6651/5 "2024-09-23T12:56:49Z")

</div>

@martines3000 I’m happy to take a look at this issue and see if I can help. Could you add me as well, please?

Github: `Torres-ssf`

---

<div class="post-metadata">

**Author:** ![Torres-ssf](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/torres-ssf/32/1380_2.png) [@Torres-ssf](https://forum.fuel.network/u/Torres-ssf)\
**Post date:** [September 23, 2024, 3:40pm UTC](https://forum.fuel.network/t/get-method-calls-dryrun-and-estimategasprice/6651/6 "2024-09-23T15:40:27Z")

</div>

@martines3000 Thanks for adding me to the project! I have a few initial observations:

### `.get()` Method

The `.get()` method should perform a `dryRun`. This simulates the contract call, allowing us to retrieve the expected response without incurring the cost of a real transaction.

### `getNodeInfo` and `getChainInfo`

The `getNodeInfo` and `getChainInfo` methods of the `Provider` class are called each time a new `Provider` instance is created with `await Provider.create(url)`.

So this means that each `await Provider.create(url)` will trigger these 2 calls.

However, the results are cached within the instance, so there’s no need to fetch this data again for subsequent calls. You can retrieve the cached data using `provider.getChain()` and `provider.getNode()`.

---

<div class="post-metadata">

**Author:** ![Torres-ssf](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/torres-ssf/32/1380_2.png) [@Torres-ssf](https://forum.fuel.network/u/Torres-ssf)\
**Post date:** [September 23, 2024, 4:18pm UTC](https://forum.fuel.network/t/get-method-calls-dryrun-and-estimategasprice/6651/7 "2024-09-23T16:18:00Z")

</div>

@martines3000 After accessing your application, I noticed that, on the main page (Dashboard), GraphQL requests are being triggered repeatedly every few seconds, even without any user interaction or a connected wallet.

Specifically, the `dryRun` (which also triggers `estimateGasPrice` as a side effect) and `balance` queries are being sent continuously.

Is there a particular reason why these requests are being made even when there is no activity on the UI?

---

<div class="post-metadata">

**Author:** ![martines3000](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/martines3000/32/3523_2.png) [@martines3000](https://forum.fuel.network/u/martines3000)\
**Post date:** [September 23, 2024, 4:44pm UTC](https://forum.fuel.network/t/get-method-calls-dryrun-and-estimategasprice/6651/8 "2024-09-23T16:44:34Z")

</div>

We had all queries set to refetch on a 10s interval. I changed this couple of hours ago and optimized it to only do this when `refetchOnWindowFocus` happens and couple of other scenarios.

Is it expected that the `.get()` requests execute `estimateGasPrice` and `dryRun` ?

---

<div class="post-metadata">

**Author:** ![martines3000](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/martines3000/32/3523_2.png) [@martines3000](https://forum.fuel.network/u/martines3000)\
**Post date:** [September 23, 2024, 4:50pm UTC](https://forum.fuel.network/t/get-method-calls-dryrun-and-estimategasprice/6651/9 "2024-09-23T16:50:28Z")

</div>

Here is a partial example of the network tab when I initially load the dapp and connect the wallet. As you can see, each of these methods is calling a read function, but 2 requests are made for each one (ignore the useTotalCollateral, as we do 3 calls here and will be changed to 1 the next time we redeploy the contract).

 ![image](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/7/7e8b33ab0c3601ef57fb6669b73fed2a5149ab1f.png)

---

<div class="post-metadata">

**Author:** ![martines3000](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/martines3000/32/3523_2.png) [@martines3000](https://forum.fuel.network/u/martines3000)\
**Post date:** [September 23, 2024, 4:51pm UTC](https://forum.fuel.network/t/get-method-calls-dryrun-and-estimategasprice/6651/10 "2024-09-23T16:51:42Z")

</div>

We also have these requests:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/7/7a64930df4ff21fc89dc9015e0a4d8351317a515.png)  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/7/7822e7ae781453cdd68fd37acd8e80820690abc5.png)

As it can be seen they happen inside the Connectors 😅

---

<div class="post-metadata">

**Author:** ![Torres-ssf](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/torres-ssf/32/1380_2.png) [@Torres-ssf](https://forum.fuel.network/u/Torres-ssf)\
**Post date:** [September 23, 2024, 6:11pm UTC](https://forum.fuel.network/t/get-method-calls-dryrun-and-estimategasprice/6651/11 "2024-09-23T18:11:31Z")

</div>

> Is it expected that the `.get()` requests execute `estimateGasPrice` and `dryRun` ?

Yes, this is expected. The `.get()` method internally performs a `dryRun`, which allows us to retrieve the contract call response without executing a real transaction and incurring costs. The `estimateGasPrice` step is necessary because, even during a `dryRun`, the gas and fees must be accurately estimated to ensure proper validation of the call.

You can use the `multiCall` feature to execute multiple contract `.get()` calls within a single `dryRun` operation:

```ts
    // the chain call can be originated for any of the used contracts
    const { value: results } = await contract1
      .multiCall([
        contract1.functions.foo(1336), 
        contract2.functions.bar(1337),
        contract3.functions.baz(1338), 
        contract1.functions.foo_2(1336), 
    ]).get();

```

The `value` property will be an array containing the returned values in the same order as the calls were made.

For example, the result of the first contract function (`contract1.functions.foo(1336)`) will be at index `0`, the second function (`contract2.functions.bar(1337)`) at index `1`, and so on.

> We also have these requests:

Are those requests `getNodeInfo` and `getChainInfo`? Are they happening for every connector instantiation?

---

<div class="post-metadata">

**Author:** ![martines3000](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/martines3000/32/3523_2.png) [@martines3000](https://forum.fuel.network/u/martines3000)\
**Post date:** [September 23, 2024, 6:26pm UTC](https://forum.fuel.network/t/get-method-calls-dryrun-and-estimategasprice/6651/12 "2024-09-23T18:26:38Z")

</div>

Thanks for the information.

Using `multiCall` would require a large refactor and it is also very inconvenient, as we currently have 1 hook for 1 contract call. I appreciate the idea 👍 .

No, the `getNodeInfo` and `getChainInfo` only happen for WalletConnect and Solana connectors. WalletConnect one happens multiple times, as seen in the screenshot.

I will also mark you last answer as the solution as it answers my question 💯

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/5/57d5a345cc15a64b636e0d56e042857f8a0e80b1.png) [@system](https://forum.fuel.network/u/system)\
**Post date:** [October 14, 2024, 2:27pm UTC](https://forum.fuel.network/t/get-method-calls-dryrun-and-estimategasprice/6651/13 "2024-10-14T14:27:15Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
