/// <summary> /// 获取交易回执单,只有交易成功的才有返回值,否则为null /// </summary> /// <param name="client"></param> /// <param name="from"></param> /// <param name="to"></param> /// <param name="value"></param> /// <param name="gas">默认值21000,</param> /// <param name="gasprice">默认值为20000000000</param> /// <returns></returns> public static string SendTransaction(this JsonRPCClient client, string from, string to, decimal value, long?gas = null, long?gasprice = null) { if (client != null && !string.IsNullOrWhiteSpace(from) && !string.IsNullOrWhiteSpace(to)) { var param = new SendTransactionParams(); param.From = from; param.To = to; if (gas > 0) { param.Gas = new HexBigInteger(BigInteger.Parse(gas.Value.ToString("f0"))).HexValue; } if (gasprice > 0) { param.GasPrice = new HexBigInteger(BigInteger.Parse(gasprice.Value.ToString("f0"))).HexValue; } SetDefaultGasPriceAndCostIfNotSet(param); param.Value = value.ToWeiHex(); var resp = client.Call <SendTransactionResponse>(JsonRPCMethods.eth_sendTransaction.ToString(), param); if (resp != null) { return(resp.Result); } } return(null); }
private static void SetDefaultGasPriceAndCostIfNotSet(SendTransactionParams transactionInput) { if (DEFAULT_GAS_LIMIT != null) { if (transactionInput.Gas == null) { transactionInput.Gas = new HexBigInteger(DEFAULT_GAS_LIMIT).HexValue; } } if (DEFAULT_GAS_PRICE != null) { if (transactionInput.GasPrice == null) { transactionInput.GasPrice = new HexBigInteger(DEFAULT_GAS_PRICE).HexValue; } } }