Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions docs/sdk.gascostestimator.gaslimitof.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@thirdweb-dev/sdk](./sdk.md) &gt; [GasCostEstimator](./sdk.gascostestimator.md) &gt; [gasLimitOf](./sdk.gascostestimator.gaslimitof.md)

## GasCostEstimator.gasLimitOf() method

Estimates the gas limit of a transaction Pass in the same parameters as the contract's function.

<b>Signature:</b>

```typescript
gasLimitOf(fn: keyof TContract["functions"] | (string & {}), args: Parameters<TContract["functions"][typeof fn]> | any[]): Promise<BigNumber>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| fn | keyof TContract\["functions"\] \| (string &amp; {}) | |
| args | Parameters&lt;TContract\["functions"\]\[typeof fn\]&gt; \| any\[\] | |

<b>Returns:</b>

Promise&lt;BigNumber&gt;

the estimated gas limit of the transaction

## Remarks

Estimates the gas limit of a transaction

## Example


```javascript
const gasLimitOfClaim = await nftDrop?.estimator.gasLimitOf("claim", [
"0x...", // receiver
1, // quantity
"0x...", // currency
1, // price per token
[], // proofs
1, // proof max quantity per transaction
]);
```

1 change: 1 addition & 0 deletions docs/sdk.gascostestimator.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ export declare class GasCostEstimator<TContract extends BaseContract>
| --- | --- | --- |
| [currentGasPriceInGwei()](./sdk.gascostestimator.currentgaspriceingwei.md) | | Returns the current gas price in gwei |
| [gasCostOf(fn, args)](./sdk.gascostestimator.gascostof.md) | | Estimates the cost of gas in native token of the current chain Pass in the same parameters as the contract's function. |
| [gasLimitOf(fn, args)](./sdk.gascostestimator.gaslimitof.md) | | Estimates the gas limit of a transaction Pass in the same parameters as the contract's function. |

9 changes: 9 additions & 0 deletions docs/snippets.json
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,15 @@
"javascript": "const costOfClaim = await nftDrop?.estimator.gasCostOf(\"claim\", [\n \"0x...\", // receiver\n 1, // quantity\n \"0x...\", // currency\n 1, // price per token\n [], // proofs\n 1, // proof max quantity per transaction\n]);"
},
"reference": "https://docs.thirdweb.com/typescript/sdk.GasCostEstimator.gasCostOf"
},
{
"name": "gasLimitOf",
"summary": "Estimates the gas limit of a transaction Pass in the same parameters as the contract's function.\n\n",
"remarks": "\n\nEstimates the gas limit of a transaction\n\n",
"examples": {
"javascript": "const gasLimitOfClaim = await nftDrop?.estimator.gasLimitOf(\"claim\", [\n \"0x...\", // receiver\n 1, // quantity\n \"0x...\", // currency\n 1, // price per token\n [], // proofs\n 1, // proof max quantity per transaction\n]);"
},
"reference": "https://docs.thirdweb.com/typescript/sdk.GasCostEstimator.gasLimitOf"
}
],
"properties": [],
Expand Down
1 change: 1 addition & 0 deletions etc/sdk.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2955,6 +2955,7 @@ export class GasCostEstimator<TContract extends BaseContract> {
constructor(contractWrapper: ContractWrapper<TContract>);
currentGasPriceInGwei(): Promise<string>;
gasCostOf(fn: keyof TContract["functions"] | (string & {}), args: Parameters<TContract["functions"][typeof fn]> | any[]): Promise<string>;
gasLimitOf(fn: keyof TContract["functions"] | (string & {}), args: Parameters<TContract["functions"][typeof fn]> | any[]): Promise<BigNumber>;
}

// @public
Expand Down
27 changes: 26 additions & 1 deletion src/core/classes/gas-cost-estimator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ContractWrapper } from "./contract-wrapper";
import { BaseContract, ethers } from "ethers";
import { BaseContract, BigNumber, ethers } from "ethers";

/**
* Estimates the gas cost of Contract calls
Expand Down Expand Up @@ -39,6 +39,31 @@ export class GasCostEstimator<TContract extends BaseContract> {
return ethers.utils.formatEther(gasUnits.mul(price));
}

/**
* Estimates the gas limit of a transaction
* Pass in the same parameters as the contract's function.
* @remarks Estimates the gas limit of a transaction
* @example
* ```javascript
* const gasLimitOfClaim = await nftDrop?.estimator.gasLimitOf("claim", [
* "0x...", // receiver
* 1, // quantity
* "0x...", // currency
* 1, // price per token
* [], // proofs
* 1, // proof max quantity per transaction
* ]);
* ```
* @returns the estimated gas limit of the transaction
* @public
*/
public async gasLimitOf(
fn: keyof TContract["functions"] | (string & {}),
args: Parameters<TContract["functions"][typeof fn]> | any[],
): Promise<BigNumber> {
return this.contractWrapper.estimateGas(fn, args);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you write a quick test for this for sanity? can just check that gasLimit > 0

}

/**
* Returns the current gas price in gwei
* @remarks Get the current gas price in gwei
Expand Down
10 changes: 10 additions & 0 deletions test/edition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ describe("Edition Contract", async () => {
expect(parseFloat(cost)).gt(0);
});

it("gas limit", async () => {
const limit = await bundleContract.estimator.gasLimitOf("mintTo", [
adminWallet.address,
ethers.constants.MaxUint256,
"mock://12398172398172389/0",
1,
]);
expect(limit.toNumber()).gt(0);
});

it("should respect pagination", async () => {
const nfts = [];
for (let i = 0; i < 100; i++) {
Expand Down