Skip to content

Commit 776737f

Browse files
committed
Gas estimation fallback for certain networks where it fails
1 parent 8b6f2a8 commit 776737f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Assets/Thirdweb/Core/Scripts/TransactionManager.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,16 @@ public static async Task<TransactionReceipt> ThirdwebWriteRawResult<TWFunction>(
5959
else
6060
{
6161
var gasEstimator = new Web3(ThirdwebManager.Instance.SDK.session.RPC).Eth.GetContractTransactionHandler<TWFunction>();
62-
var gas = await gasEstimator.EstimateGasAsync(contractAddress, functionMessage);
63-
functionMessage.Gas = gas.Value < 100000 ? 100000 : gas.Value;
62+
functionMessage.Gas = 100000;
63+
try
64+
{
65+
var gas = await gasEstimator.EstimateGasAsync(contractAddress, functionMessage);
66+
functionMessage.Gas = gas.Value < 100000 ? 100000 : gas.Value;
67+
}
68+
catch (System.Exception e)
69+
{
70+
Debug.LogWarning($"Failed to estimate gas for transaction, proceeding with 100k gas: {e.Message}");
71+
}
6472
}
6573

6674
bool isGasless = ThirdwebManager.Instance.SDK.session.Options.gasless.HasValue && ThirdwebManager.Instance.SDK.session.Options.gasless.Value.openzeppelin.HasValue;

0 commit comments

Comments
 (0)