Skip to content

Commit

Permalink
[GD-55] Add gas estimation function (#2)
Browse files Browse the repository at this point in the history
* Add gas estimation function

* Fix example
  • Loading branch information
sidorovkirill authored Mar 16, 2022
1 parent 47013bb commit 41e9623
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public async void UpdateNFT()
Debug.Log($"Receipt: {receipt}");
}

public async void EstimateGas()
{
var info = await RequestPreparedParams(0);
var gasEstimation = await _contract.EstimateGas("updateTokenWithSignedMessage", new object[] {info});
Debug.Log("Gas estimation = "+gasEstimation);
}

private async Task<ItemInfo> RequestPreparedParams(int tokenId)
{
var request = UnityWebRequest.Get(URL + $"hero/{tokenId}");
Expand Down
14 changes: 14 additions & 0 deletions Assets/AnkrSDK/Scripts/Core/Implementation/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Cysharp.Threading.Tasks;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts;
using Nethereum.Hex.HexTypes;
using Nethereum.RPC.Eth.DTOs;
using Nethereum.Web3;

Expand Down Expand Up @@ -108,5 +109,18 @@ private TransactionInput CreateTransactionInput(string methodName, object[] argu
var callFunction = contract.GetFunction(methodName);
return callFunction.CreateTransactionInput(activeSessionAccount, arguments);
}


public Task<HexBigInteger> EstimateGas(string methodName, object[] arguments = null, string gas = null,
string gasPrice = null, string nonce = null)
{
var transactionInput = CreateTransactionInput(methodName, arguments);

transactionInput.Gas = gas != null ? new HexBigInteger(gas) : null;
transactionInput.GasPrice = gasPrice != null ? new HexBigInteger(gasPrice) : null;
transactionInput.Nonce = nonce != null ? new HexBigInteger(nonce) : null;

return _web3Provider.TransactionManager.EstimateGasAsync(transactionInput);
}
}
}
4 changes: 4 additions & 0 deletions Assets/AnkrSDK/Scripts/Core/Infrastructure/IContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using AnkrSDK.Core.Events;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts;
using Nethereum.Hex.HexTypes;

namespace AnkrSDK.Core.Infrastructure
{
Expand All @@ -20,5 +21,8 @@ Task<List<EventLog<TEvDto>>> GetAllChanges<TEvDto>(EventFilterData evFilter = nu

Task<TReturnType> GetData<TFieldData, TReturnType>(TFieldData requestData = null)
where TFieldData : FunctionMessage, new();

Task<HexBigInteger> EstimateGas(string methodName, object[] arguments = null, string gas = null,
string gasPrice = null, string nonce = null);
}
}

0 comments on commit 41e9623

Please sign in to comment.