Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a note about gas estimation issue #598

Merged
merged 2 commits into from
Aug 16, 2024
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
4 changes: 4 additions & 0 deletions docs/develop/nova/foundry_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,8 @@ keywords:
Do not attempt to speed up a transaction (do not include a tip on top of the gas fees). To read more about this, please refer to [this section](quick_start.md#important-note-about-submitting-the-transaction).
:::

:::caution
In some cases when deploying the script, you may experience **"No manual gas limit set"** or **"Gas estimation failed"** issues. Please refer to [this section](/docs/develop/nova/quick_start.md#gas-estimation-issue) for the solution.
:::

8. **Congratulations**, you've successfully deployed your smart contract on Autonomys EVM!
4 changes: 4 additions & 0 deletions docs/develop/nova/hardhat_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,8 @@ In case of success deployment, you should see `Contract deployed to: transaction

![Hardhat-6](/img/developers/Hardhat-6.png)

:::caution
In some cases when deploying the script, you may experience **"No manual gas limit set"** or **"Gas estimation failed"** issues. Please refer to [this section](/docs/develop/nova/quick_start.md#gas-estimation-issue) for the solution.
:::

11. **Congratulations**, you've successfully deployed your smart contract on the Autonomys EVM domain!
74 changes: 74 additions & 0 deletions docs/develop/nova/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,80 @@ If anything above sounds unfamiliar, you can always fall back to our full guide.

Please avoid attempting to accelerate a transaction by including a tip alongside the gas fees. The transaction queue operates differently with Autonomys, leading to the possibility of two transactions sharing the same nonce. This could result in dual charges for gas fees - once for the execution and storage in the first transaction, and solely for storage in the second transaction. To prevent this scenario, ensure that you refrain from adding a tip in an attempt to speed the transaction up.

---
### Gas Estimation Issue

When deploying smart contracts to our EVM-compatible domain **Nova**, you may encounter an error related to gas estimation, typically presenting as:

`"No manual gas limit set" or "Gas estimation failed"`.

This issue often occurs because development tools like Foundry simulate transactions and use calculated or hardcoded gas estimation instead of querying the RPC (Remote Procedure Call) for it. **Nova** may require different gas amounts for certain operations compared to other EVM-compatible chains like Ethereum's testnets.

:::note
We have submitted an upstream PR to fix this issue with **Foundry**. Described below are the workarounds, until the issue is resolved by the **Foundry team**.
:::

#### Solutions

If you encounter this issue, try the following solutions:

- Skip simulation: Use the `--skip-simulation` flag when deploying with Foundry to bypass built-in simulation and rely on RPC for gas estimation.

- Set manual gas limit: Specify a higher gas limit manually in your deployment command or UI.

- Adjust deployment script: Modify your script to include custom gas settings or implement `try/catch` blocks for handling deployment failures.

- Use Web3 provider: If using **Remix IDE**, switch to `Injected Web3` environment to leverage external Web3 providers like MetaMask.

- Custom deployment function: Create a deployment function with adjustable gas parameters.


#### Solution examples

**Foundry**

1. Try using `--skip-simulation` flag: `forge script path/to/your/script.s.sol --rpc-url your_rpc_url --private-key your_private_key --broadcast --skip-simulation`.

2. Try setting the gas limit manually: `forge script path/to/your/script.s.sol --rpc-url your_rpc_url --private-key your_private_key --broadcast --gas-limit 300000`.

Adjust the gas limit value as needed. Start with a higher value and gradually lower it to find the optimal limit.

**Remix IDE**

1. Try settiing gas limit manually: In the **Deploy & Run Transactions** panel, expand the **Advanced** section.
Set a higher value in the **Gas Limit** field. Try starting with **300000** and adjust as needed.

2. Try adjusting gas price: In the same **Advanced** section, you can also adjust the **Gas Price** if needed.

3. Try switching to the **Injected Web3** environment in the **Deploy & Run Transactions** panel. This will use your browser's Web3 provider (like MetaMask) which might handle gas estimation better for the network.

4. If the above steps don't work, you can create a custom deployment function that includes gas parameters:

```
function deployWithCustomGas(uint256 gasLimit, uint256 gasPrice) public returns (address) {
return address(new YourContract{gas: gasLimit, gasPrice: gasPrice}());
}
```

**Other possible solution**

1. Modify your deployment script and override the default gas settings:

```
vm.txGasPrice(uint256 gasPrice);
vm.txGasLimit(uint256 gasLimit);
```

2. Implement a try/catch block in your script to handle gas estimation failures:

```
try yourContract.deploy{gas: 300000}(constructorArgs) returns (YourContract deployed) {
// Deployment successful
} catch Error(string memory reason) {
console.log("Deployment failed:", reason);
}
```

---

### Have any questions? Feel free to post them on [our forum](https://forum.autonomys.xyz/) or in our [Developer-chat on Discord](https://discord.gg/EAw6B48r).
Expand Down
6 changes: 5 additions & 1 deletion docs/develop/nova/remix_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ Now your transaction is recorded and you can interact with your smart contract a
Do not attempt to speed up a transaction (do not include a tip on top of the gas fees). To read more about this, please refer to [this section](quick_start.md#important-note-about-submitting-the-transaction).
:::

![Remix-12](/img/developers/Remix-12.png)
:::caution
In some cases when deploying the script, you may experience **"No manual gas limit set"** or **"Gas estimation failed"** issues. Please refer to [this section](/docs/develop/nova/quick_start.md#gas-estimation-issue) for the solution.
:::

![Remix-12](/img/developers/Remix-12.png)

Congratulations, you've just deployed your smart contract on Autonomys Core EVM!