Example #1
0
        /// <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);
        }
Example #2
0
        /// <summary>
        /// Sends a message to an ethereum smart contract with the intent to change a part of the contract on the blockchain.
        /// </summary>
        /// <typeparam name="TFunc"> The <see cref="FunctionMessage"/> to execute on the blockchain given the contract address. </typeparam>
        /// <param name="function"> The function to execute. </param>
        /// <param name="contractAddress"> The contract address to execute the <see cref="FunctionMessage"/> on. </param>
        /// <param name="privateKey"> The private key of the address sending the transaction. </param>
        /// <param name="gasPrice"> The <see cref="BigInteger"/> gas price to use with the transaction. </param>
        /// <returns> Promise of the transaction result of sending the contract message. </returns>
        public static EthTransactionPromise SendContractMessage <TFunc>(
            TFunc function,
            string contractAddress,
            string privateKey,
            BigInteger gasPrice) where TFunc : FunctionMessage
        {
            EthECKey ethKey  = new EthECKey(privateKey);
            var      promise = new EthTransactionPromise();

            GasUtils.EstimateContractGasLimit(function, contractAddress, ethKey.GetPublicAddress())
            .OnSuccess(gasLimit => _SendContractMessageCoroutine(function, promise, contractAddress, privateKey, gasPrice, gasLimit).StartCoroutine());

            return(promise);
        }