public static async Task <MaticTransactionOptions> GetTransactionEstimate(ERC20WithdrawModel withdrawModel, MaticTransactionOptions options, Function function) { try { //Get the Account and set up the sender's Address Account account = GetAccount(options.SenderPrivateKey, options.ChainId); //Get the Gas Limit HexBigInteger gasLimit = await function.EstimateGasAsync(account.Address, null, null, withdrawModel.Amount); //Get the Gas Price Estimate GasPriceEstimator gasPriceEstimator = new GasPriceEstimator(); GasPriceEstimate gasPriceEstimate = await gasPriceEstimator.GetRecommendedGasPriceFromNetwork(); //Fill the options options.GasPrice = (decimal)gasPriceEstimate.AverageGwei; options.GasLimit = gasLimit; options.From = account.Address; return(options); } catch (Exception ex) { throw new Exception("Could not Fetch the Transaction Estimate because " + ex.Message); } }
public static async Task <MaticTransactionOptions> GetTransactionEstimate(ERC20ApproveModel approveModel, MaticTransactionOptions options, Function function) { try { //Get the Account of the Sender Account account = GetAccount(options.SenderPrivateKey, options.ChainId); //Get the Gas Limit HexBigInteger gasLimit = await function.EstimateGasAsync(account.Address, null, null, approveModel.Spender, (BigInteger)approveModel.Value); //Get the Gas Price Estimate GasPriceEstimator gasPriceEstimator = new GasPriceEstimator(); GasPriceEstimate gasPriceEstimate = await gasPriceEstimator.GetRecommendedGasPriceFromNetwork(); //Fill the options options.GasPrice = (decimal)gasPriceEstimate.AverageGwei; options.GasLimit = gasLimit; options.From = account.Address; return(options); } catch (Exception ex) { throw new Exception("Failed to Fill options because " + ex.Message); } }
public static async Task <MaticTransactionOptions> GetTransactionEstimate(WithdrawBurntTokensModel withdrawModel, MaticTransactionOptions options, Function function) { try { //Get the Account of the Sender Account account = GetAccount(options.SenderPrivateKey, options.ChainId); //Get the Gas Limit HexBigInteger gasLimit = await function.EstimateGasAsync(account.Address, null, null, withdrawModel.HeaderNumber, withdrawModel.HeaderProof, withdrawModel.BlockNumber, withdrawModel.BlockTimeStamp, withdrawModel.TxRoot, withdrawModel.ReceiptProof, withdrawModel.Path, withdrawModel.TxBytes, withdrawModel.TxProof, withdrawModel.ReceiptBytes, withdrawModel.ReceiptProof); //Get the Gas Price Estimate GasPriceEstimator gasPriceEstimator = new GasPriceEstimator(); GasPriceEstimate gasPriceEstimate = await gasPriceEstimator.GetRecommendedGasPriceFromNetwork(); //Fill the options options.GasPrice = (decimal)gasPriceEstimate.AverageGwei; options.GasLimit = gasLimit; options.From = account.Address; return(options); } catch (Exception ex) { throw new Exception("Failed to Fill options because " + ex.Message); } }
public static async Task <MaticTransactionOptions> GetTransactionEstimate(DepositModel depositModel, MaticTransactionOptions options, Function function) { try { //Get the Account of the Sender options.ChainId = Chain.Ropsten; Account account = GetAccount(options.SenderPrivateKey, options.ChainId); //Get the Gas Price Estimate GasPriceEstimator gasPriceEstimator = new GasPriceEstimator(); GasPriceEstimate gasPriceEstimate = await gasPriceEstimator.GetRecommendedGasPriceFromNetwork(); //Get the Gas Limit HexBigInteger gasLimit = new HexBigInteger(4712388); //HexBigInteger gasLimit = await function.EstimateGasAsync(depositModel); //Fill the options options.GasPrice = (decimal)gasPriceEstimate.AverageGwei; options.GasLimit = gasLimit; options.From = account.Address; return(options); } catch (Exception ex) { throw new Exception("Failed to Fill options because " + ex.Message); } }
public static async Task <MaticTransactionOptions> GetTransactionEstimate(MaticTransactionOptions options, Function function) { try { //Get the Account and set up the sender's Address Account account = GetAccount(options.SenderPrivateKey, options.ChainId); //Get the Gas Limit HexBigInteger gasLimit = await function.EstimateGasAsync(account.Address, null, new HexBigInteger(options.Value.ToString())); //Get the Gas Price Estimate GasPriceEstimator gasPriceEstimator = new GasPriceEstimator(); GasPriceEstimate gasPriceEstimate = await gasPriceEstimator.GetRecommendedGasPriceFromNetwork(); //Fill the options options.GasPrice = (decimal)gasPriceEstimate.AverageGwei; options.GasLimit = gasLimit; options.From = account.Address; return(options); } catch (Exception ex) { throw new Exception($"There was an error fetching the transaction estimate because {ex.Message}"); } }
public async Task <GasPriceEstimate> GetRecommendedGasPriceFromNetwork() { HttpClient client = new HttpClient(); client.BaseAddress = new Uri("https://ethgasstation.info/"); var response = await client.GetAsync("json/ethgasAPI.json"); if (response.StatusCode == HttpStatusCode.OK) { string contentString = await response.Content.ReadAsStringAsync(); EthGasStationResponse ethGasStationResponse = JsonConvert.DeserializeObject <EthGasStationResponse>(contentString); GasPriceEstimate gasPriceEstimate = new GasPriceEstimate { LowGwei = ethGasStationResponse.safeLow, AverageGwei = ethGasStationResponse.average, FastGwei = ethGasStationResponse.fast, }; return(gasPriceEstimate); } throw new Exception($"Fetching Of Recommended Gas Price Returned Status Code {response.StatusCode}"); }