reown-com / reown-dotnet

Toolkits to build onchain UX
https://docs.reown.com/
Apache License 2.0
8 stars 1 forks source link

Unity ReownNetworkException:intrinsic gas too low: gas 0, minimum needed 21604 #13

Open shekaryf opened 3 weeks ago

shekaryf commented 3 weeks ago

I deployed a super simple .sol class that has set and get functions.

Now I want to write contract calling set; here is my code:

On deploying I tested with custom and estimated gas and problem not solved.

const string contractAddress = "xxxx";
const string abi = "...";
string writeTxt = "Hi testing ";
Debug.Log($"writeTxt: {writeTxt}");

await AppKit.Evm.WriteContractAsync(contractAddress, abi, "set", new object[]
{
    writeTxt,
});

ERROR:
ReownNetworkException: intrinsic gas too low: gas 0, minimum needed 21604
Reown.Sign.Engine.Request[T,TR] (System.String topic, T data, System.String chainId, System.Nullable 1[T] expiry) (at src/Reown.Sign/Runtime/Engine.cs:734)
Reown.Sign.Nethereum.ReownSignServiceCore.SendTransactionAsyncCore (Nethereum.RPC.Eth.DTOs.TransactionInput transaction) (at src/Reown.Sign.Nethereum/Runtime/ReownSignServiceCore.cs:55)
Reown.Sign.Nethereum.ReownInterceptor.InterceptSendRequestAsync[T] (System.Func 3[T1,T2,TResult] interceptedSendRequestAsync, Nethereum.JsonRpc.Client.RpcRequest request, System.String route) (at src/Reown.Sign.Nethereum/Runtime/ReownInterceptor.cs:48)
Nethereum.JsonRpc.Client.ClientBase.SendRequestAsync[T] (Nethereum.JsonRpc.Client.RpcRequest request, System.String route) (at <bc5ab06f005041149e3762f63c0c00e2>:0)
Nethereum.RPC.TransactionManagers.TransactionManager.SendTransactionAsync (Nethereum.RPC.Eth.DTOs.TransactionInput transactionInput) (at <7cfdb02465d548458634c58a629e8e84>:0)
Reown.AppKit.Unity.NethereumEvmService.WriteContractAsyncCore (System.String contractAddress, System.String contractAbi, System.String methodName, System.Numerics.BigInteger value, System.Numerics.BigInteger gas, System.Object[] arguments) (at src/Reown.AppKit.Unity/Runtime/Evm/NethereumEvmService.cs:125)
Sample.Dapp.OnWriteContractClicked () (at Assets/Scripts/Dapp.cs:349)
UnityEngine.Debug:LogException(Exception, Object)
Sample.<OnWriteContractClicked>d__15:MoveNext() (at Assets/Scripts/Dapp.cs:363)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder 1:SetException(Exception)
Reown.AppKit.Unity.<WriteContractAsyncCore>d__17:MoveNext() (at src/Reown.AppKit.Unity/Runtime/Evm/NethereumEvmService.cs:125)
UnityEngine.UnitySynchronizationContext:ExecuteTasks()

I used this code:

                await AppKit.Evm.WriteContractAsync(contractAddress, abi, "set", new BigInteger(3000000), new object[]
                {
                    writeTxt,
                });

and error passed. Is there any way for default value or estimation ?

Thanks

skibitsky commented 3 weeks ago

Hello,

Gas estimation will be added in the next release. In the meantime, as a temporary workaround, you should be able to use Nethereum directly:

var nethereumSerice = AppKit.Evm as NethereumEvmService;
var contract = nethereumSerice.Web3.Eth.GetContract(contractAbi, contractAddress);
var function = contract.GetFunction(methodName);

var transactionInput = new TransactionInput(function.GetData(arguments), contractAddress, new HexBigInteger(value));

var gasLimit = await nethereumSerice.Web3.Eth.Transactions.EstimateGas.SendRequestAsync(transactionInput);
var gasPrice = await nethereumSerice.Web3.Eth.GasPrice.SendRequestAsync();

This will work on all platforms except WebGL, sorry for the inconvenience 🙏

shekaryf commented 3 weeks ago

Thanks