/// <summary> /// Estimates the gas limit of a certain function of a contract. /// </summary> /// <param name="promise"> Promise of the estimated gas limit of a transaction. </param> /// <param name="callInput"> The transaction input to estimate the gas limit for. </param> /// <param name="overEstimate"> Whether the gas limit should be slightly overestimated. </param> /// <returns> The time taken to retrieve the estimated gas limit. </returns> private static IEnumerator _EstimateGasLimitCoroutine(EthCallPromise <BigInteger> promise, CallInput callInput, bool overEstimate) { var request = new EthEstimateGasUnityRequest(EthereumNetworkManager.CurrentNetwork.NetworkUrl); yield return(request.SendRequest(callInput)); promise.Build(request, () => overEstimate ? (request.Result.Value * 100 / 90) : request.Result.Value); }
/// Sets the DNA based on the input fields /// 1. Estimate Gas parameter /// 2. Send transaction /// 3. Wait for receipt private IEnumerator SetDNA() { string wallet = inputWallet.text; string privateKey = inputPrivateKey.text; var contract = new Contract(null, itemManagerABI, itemManagerContractAddress); var function = contract.GetFunction("setDNA"); EthEstimateGasUnityRequest estimateRequest = new EthEstimateGasUnityRequest(url); // convert string to hex to work the same way as Javascript Example string id = int.Parse(inputSetDNAItemID.text).ToString("x"); string hexString = System.Numerics.BigInteger.Parse(inputSetDNADNA.text).ToString("x"); TransactionInput estimateInput = function.CreateTransactionInput(wallet, id, hexString); yield return(estimateRequest.SendRequest(estimateInput)); if (estimateRequest.Exception != null) { Debug.Log(estimateRequest.Exception); yield break; } Debug.Log("Gas: " + estimateRequest.Result.Value); var req = new TransactionSignedUnityRequest(url, privateKey, wallet); var callInput = function.CreateTransactionInput( wallet, estimateRequest.Result, new HexBigInteger("0x0"), id, hexString); yield return(req.SignAndSendTransaction(callInput)); textSetDNAStatus.text = "waiting"; var receiptRequest = new EthGetTransactionReceiptUnityRequest(url); bool done = false; while (!done) { yield return(receiptRequest.SendRequest(req.Result)); if (receiptRequest.Result != null) { done = true; } yield return(new WaitForSeconds(1.0f)); } textSetDNAStatus.text = "done"; }