/// <summary> /// Sends ether from this wallet to a given address. /// </summary> /// <param name="privateKey"> The private key of the address sending the transaction. </param> /// <param name="addressTo"> The address to send the ether to. </param> /// <param name="amount"> The amount of ether to send. </param> /// <param name="gasPrice"> The gas price of the ether send transaction. </param> /// <returns> The promise which will contain the result of a successful/unsuccessful transaction. </returns> public static EthTransactionPromise SendEther( string privateKey, string addressTo, decimal amount, BigInteger gasPrice) { var promise = new EthTransactionPromise(); GasUtils.EstimateEthGasLimit(addressTo, SolidityUtils.ConvertToUInt(amount, 18)) .OnSuccess(gasLimit => _SendEtherCoroutine(promise, gasLimit, gasPrice, privateKey, addressTo, amount).StartCoroutine()); return(promise); }
/// <summary> /// Sends ether from one address to another. /// </summary> /// <param name="promise"> Promise of the transaction result of sending ether. </param> /// <param name="walletAddress"> The address of the wallet sending the ether. </param> /// <param name="gasLimit"> The gas limit of the ether send transaction. </param> /// <param name="gasPrice"> The gas price of the ether send transaction. </param> /// <param name="privateKey"> The private key of the address sending the transaction. </param> /// <param name="addressTo"> The address the ether is being sent to. </param> /// <param name="amount"> The amount to send in ether. </param> /// <returns> The time waited for the request to be broadcast to the network. </returns> private static IEnumerator _SendEtherCoroutine( EthTransactionPromise promise, BigInteger gasLimit, BigInteger gasPrice, string privateKey, string addressTo, dynamic amount) { EthECKey ethKey = new EthECKey(privateKey); TransactionSignedUnityRequest unityRequest = new TransactionSignedUnityRequest(NetworkProvider.GetNetworkChainUrl(), privateKey, ethKey.GetPublicAddress()); TransactionInput transactionInput = new TransactionInput("", addressTo, ethKey.GetPublicAddress(), new HexBigInteger(gasLimit), new HexBigInteger(gasPrice), new HexBigInteger(SolidityUtils.ConvertToUInt(amount, 18))); yield return(unityRequest.SignAndSendTransaction(transactionInput)); promise.Build(unityRequest, () => unityRequest.Result, () => NetworkProvider.GetNetworkChainUrl()); }