public string Call(Transaction transaction) { var rpcRequest = new RpcRequest(RpcMethod.eth_call); rpcRequest.AddParam(transaction); rpcRequest.AddParam(BlockTag.Latest.ToJsonMethodName()); var rpcResult = new RpcConnector().MakeRequest(rpcRequest); return rpcResult.Result; }
public string EstimateGas(Transaction transaction) { var rpcRequest = new RpcRequest(RpcMethod.eth_estimateGas); rpcRequest.AddParam(transaction); var rpcResult = new RpcConnector().MakeRequest(rpcRequest); string gas = rpcResult.Result.ToString(); //var estimatedGas = gas.HexToInt(); return gas; }
public static string TransactionHtml(Transaction tx) { var html = Header(); html += string.Format("<div>Hash : {0}</div>", tx.Hash); html += string.Format("<div>Nonce : {0}</div>", tx.Nonce); html += string.Format("<div>From : {0}</div>", tx.From); html += string.Format("<div>To : {0}</div>", tx.To); html += Footer(); return html; }
public void EstimateGas() { var account = BlockStudioProject.DefaultAccount; var bin = GetFile(SolcProjectFileType.Bin); var transaction = new Transaction() { From = account.Address, Data = bin.Value }; var estimatedGas = BlockStudioProject.Connection.EthereumService.EstimateGas(transaction); _txtEstimatedGas.Text = estimatedGas.ToString(); }
private void btnPublish_Click(object sender, EventArgs e) { var accountValue = cmbAccounts.SelectedItem; if (accountValue == null) { var result = MessageBoxEx.Show(this, string.Format("Select an account to publish from"), "Block Studio", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } var account = (Account) accountValue; if (account.Balance < 10000000) { var result = MessageBoxEx.Show(this, string.Format("You do not have enough Ether to publish the contract"), "Block Studio", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } var bin = BlockStudioProjectService.GetFile(SolcProjectFileType.Bin); if (bin==null) { var result = MessageBoxEx.Show(this, string.Format("It appears there is no bytecode generated for this project"), "Block Studio", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } var transaction = new Transaction() { From = account.Address, Data = bin.Value, Gas = txtEstimateGas.Text }; BlockStudioProjectService.PublishedTxHash = BlockStudioProjectService.BlockStudioProject.Connection.EthereumService.SendTransaction(transaction); _ethereumFilterManager.AddBlockPendingFilter(BlockStudioProjectService.PublishedTxHash); _ethereumFilterManager.Start(); txtBuildOutput.WriteConsonsoleMessage("contract published with code: {0}", BlockStudioProjectService.GetFile(SolcProjectFileType.Bin).Value); }
public string SendTransaction(Transaction transaction) { var rpcRequest = new RpcRequest(RpcMethod.eth_sendTransaction); rpcRequest.AddParam(transaction); var rpcResult = new RpcConnector().MakeRequest(rpcRequest); return rpcResult.Result; }
/// <summary> /// Creates new message call transaction or a contract creation, if the data field contains code. /// </summary> /// <param name="from">The address the transaction is send from.</param> /// <param name="to">(optional when creating new contract) The address the transaction is directed to.</param> /// <param name="gas">(optional, default: 90000) Integer of the gas provided for the transaction execution. It will return unused gas.</param> /// <param name="data">(optional) The compiled code of a contract</param> /// <param name="gasPrice">(optional, default: To-Be-Determined) Integer of the gasPrice used for each paid gas</param> /// <param name="value">(optional) Integer of the value send with this transaction</param> /// <param name="nonce">(optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.</param> /// <returns>the transaction hash, or the zero hash if the transaction is not yet available.</returns> public string SendTransaction(string from, string to, int gas, string data, int gasPrice = -1, int value = -1, int nonce = -1) { var rpcRequest = new RpcRequest(RpcMethod.eth_sendTransaction); var transactionParams = new Transaction(); transactionParams.To = to; if (from != null) transactionParams.From = from; if (data != null) transactionParams.Data = data; if (gas > -1) transactionParams.Gas = gas.ToHexString(); if (gasPrice > -1) transactionParams.GasPrice = gas.ToHexString(); if (value > -1) transactionParams.Value = value.ToHexString(); if (nonce > -1) transactionParams.Nonce = nonce.ToHexString(); rpcRequest.AddParam(transactionParams); var rpcResult = new RpcConnector().MakeRequest(rpcRequest); return rpcResult.Result; }
private void btnSend_Click(object sender, EventArgs e) { var value = txtAmount.Text.ToBigInteger(NumberStyles.Integer); value = value*1000000000000000000; var transaction = new Transaction() { To = txtSendTo.Text, From = cmdAccounts.SelectedItem.ToString(), Value = value.ToHexString() }; var txHash = EthereumService.SendTransaction(transaction); var sendTxHistory = new SendTxHistory() { DateTime = DateTime.Now.ToString(), Amount = transaction.Value.ToBigInteger().WeiToEther(), Hash = txHash }; SendTxHistoryList.Add(sendTxHistory); dgSendTransactions.DataSource = null; dgSendTransactions.DataSource = SendTxHistoryList; SetGridWidth(); txtTransactionHash.Text = txHash; // MessageBox.Show(txHash, "Transaction"); }