Exemplo n.º 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>
        /// <returns> The promise which will contain the result of a successful/unsuccessful transaction. </returns>
        public static EthTransactionPromise SendEther(
            string privateKey,
            string addressTo,
            decimal amount)
        {
            var promise = new EthTransactionPromise();

            GasUtils.EstimateEthGasLimit(addressTo, SolidityUtils.ConvertToUInt(amount, 18))
            .OnSuccess(gasLimit => GasUtils.EstimateGasPrice()
                       .OnSuccess(gasPrice => _SendEtherCoroutine(promise, gasLimit, gasPrice, privateKey, addressTo, amount).StartCoroutine()));

            return(promise);
        }
Exemplo n.º 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>
        /// <returns> Promise of the transaction result of sending the contract message. </returns>
        public static EthTransactionPromise SendContractMessage <TFunc>(
            TFunc function,
            string contractAddress,
            string privateKey) where TFunc : FunctionMessage
        {
            EthECKey ethKey  = new EthECKey(privateKey);
            var      promise = new EthTransactionPromise();

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

            return(promise);
        }