These are chat archives for Nethereum/Nethereum

7th
Jul 2017
antonovvi87
@antonovvi87
Jul 07 2017 09:03 UTC
Hello, as I understood, each transaction should has a nonce parameter. But there no deploy cotract methods with nonce parameter. When I create transactions whithout nonce parameter I can find them only in my local node. And they always have status pending.
Hernan Brunstein
@herbru
Jul 07 2017 12:51 UTC
hi, i want to send ether to a payable function in my contract, but i have problems with the parameters, how should they look like?
the parameters are from a transaction
Juan Blanco
@juanfranblanco
Jul 07 2017 13:45 UTC
@antonovvi87 maybe you are not mining?
the nonce is created in order by the client, or when signing offline is retrived for you to sing the transactions
@herbru if you are sending to a payeable function the best thing is to use the abi get the function and then send an amount to it
you should convert it from wei
if this "i am guessing" for an ico, test it first :D
Carlos Muñoz
@carlosm2011835_twitter
Jul 07 2017 17:05 UTC

I'm having trouble with the following: You can verify an encoded transaction:

Assert.True(web3.OfflineTransactionSigning.VerifyTransaction(encoded));

I'm getting the error that it's not letting me use assert
The error reads "CS0103 The name 'Assert' does not exist in the current context"
Carlos Muñoz
@carlosm2011835_twitter
Jul 07 2017 17:17 UTC
I guess I'm wondering which library you're using because that's not clear to me
Juan Blanco
@juanfranblanco
Jul 07 2017 17:50 UTC
Xunit
@carlosm2011835_twitter
Carlos Muñoz
@carlosm2011835_twitter
Jul 07 2017 17:50 UTC
Ok thank you
Juan Blanco
@juanfranblanco
Jul 07 2017 17:51 UTC
that is picked up from the Unit tests you don't need to
use it
Carlos Muñoz
@carlosm2011835_twitter
Jul 07 2017 17:55 UTC
I may be misunderstanding the purpose of web3.OfflineTransactionSigning.VerifyTransaction(encoded)
Is it only for testing purposes? Or is it's purpose to verify that a transaction has been encoded correctly?
Juan Blanco
@juanfranblanco
Jul 07 2017 17:56 UTC
sorry Assert is for unit testing
and verify the transaction signing, mainly validates the signature
Carlos Muñoz
@carlosm2011835_twitter
Jul 07 2017 18:00 UTC
So from what I understand I can just write something like
        if (web3.OfflineTransactionSigning.VerifyTransaction(encoded))
        {
            Console.WriteLine("Transaction signing was validated");

        }
        else
        {
            Console.WriteLine("Transaction was not validated");
        }
Another problem I had was that
var encoded = web3.OfflineTransactionSigning.SignTransaction(privateKey, receiveAddress, 10, txCount.Value);
gives me an error saying that the 4th argument which is txCount.Value cannot be converted from method group to BigInteger
Juan Blanco
@juanfranblanco
Jul 07 2017 18:02 UTC
that is async
you need to awaited
await* the call
Carlos Muñoz
@carlosm2011835_twitter
Jul 07 2017 18:04 UTC
    async static void PushTransaction()
    {
        string receiveAddress = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"; //Main
        var privateKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"; // Backup
        var senderAddress = Nethereum.Core.Signing.Crypto.EthECKey.GetPublicAddress(privateKey);
        var web3 = new Web3();
        var txCount = web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(senderAddress);
        var encoded = await web3.OfflineTransactionSigning.SignTransaction(privateKey, receiveAddress, 10, txCount.Value);
        Console.WriteLine("\nsenderAddress: " + senderAddress + "\nTxCount: " + txCount + "\nEncoded Transaction" + encoded);
        Assert.True(web3.OfflineTransactionSigning.VerifyTransaction(encoded));
        Console.WriteLine("Transaction is about to be pushed");
        Console.WriteLine("Are you sure you want to push transaction");
        var txId = web3.Eth.Transactions.SendRawTransaction.SendRequestAsync("0x" + encoded);
    }
ahh I see I switched them around txCount should be await and encoded should not be await
Juan Blanco
@juanfranblanco
Jul 07 2017 18:06 UTC
yes
what are you trying to do?
obviously sign a transaction
you may find this new way better
Carlos Muñoz
@carlosm2011835_twitter
Jul 07 2017 18:09 UTC
I'm trying to transfer between accounts
:)
I'll look at that
Juan Blanco
@juanfranblanco
Jul 07 2017 18:09 UTC
ah well that is an spot on sample then
Carlos Muñoz
@carlosm2011835_twitter
Jul 07 2017 18:17 UTC
I made the references for using Nethereum.Web3.Accounts;
using Nethereum.Web3.Accounts.Managed;
using Nethereum.Web3.TransactionReceipts;
Juan Blanco
@juanfranblanco
Jul 07 2017 18:18 UTC
yep
Carlos Muñoz
@carlosm2011835_twitter
Jul 07 2017 18:19 UTC
And I added Nethereum.Portable Nethereum.RPC, Nethereum.Web3, Nethereum.JsonRPC.Client, Nethereum.Hex, and Nethereum.ABI
but I'm getting an error that says type or namespace Accounts does not exist in Nethereum.Web3
same for transaction receipts
Carlos Muñoz
@carlosm2011835_twitter
Jul 07 2017 19:03 UTC
I think the problem is that I got those through nuget and the one on Github is different
Carlos Muñoz
@carlosm2011835_twitter
Jul 07 2017 20:29 UTC
All right so I downloaded the library from Github, I opened Nethereum.Portable.csproj and I have now build the solution. After building the solution I grabbed the .dll from from Nethereum.Portable\bin\Debug. Now when I run my program I get unhandled exception
var currentBalance = await web3.Eth.GetBalance.SendRequestAsync(addressTo);

An unhandled exception of type 'System.MissingMethodException' occurred in mscorlib.dll

Additional information: Method not found: '!!0 EdjCase.JsonRpc.Client.RpcResponseExtensions.GetResult(EdjCase.JsonRpc.Core.RpcResponse, Boolean, Newtonsoft.Json.JsonSerializerSettings)'.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using RestSharp;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Nethereum.Hex.HexTypes;
using Nethereum.Web3.Accounts;
using Nethereum.Web3.Accounts.Managed;
using Nethereum.Web3.TransactionReceipts;
using Nethereum.Web3;
using Xunit;
//using Microsoft.VisualStudio.TestTools.UnitTesting;
//using System.Web.Script.Serialization;

namespace ETHTransfer
{
class Program
{
static void Main(string[] args)
{

            PushTransaction();

    }

   public async static void PushTransaction()
    {
        var senderAddress = "xxxxxxxxxxxxxxxxxxxxxxxxx";
        var addressTo = "xxxxxxxxxxxxxxxxxxx";
        var password = "password";

        var privateKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";


        // The default account is an account which is mananaged by the user

        var account = new Account(privateKey);
        var web3 = new Web3(account);

        //The transaction receipt polling service is a simple utility service to poll for receipts until mined
        var transactionPolling = new TransactionReceiptPollingService(web3);

        var currentBalance = await web3.Eth.GetBalance.SendRequestAsync(addressTo);
        Console.WriteLine("here");
        //assumed client is mining already

        //when sending a transaction using an Account, a raw transaction is signed and send using the private key
        var transactionReceipt = await transactionPolling.SendRequestAsync(() =>
            web3.TransactionManager.SendTransactionAsync(account.Address, addressTo, new HexBigInteger(20))
        );

        var newBalance = await web3.Eth.GetBalance.SendRequestAsync(addressTo);

        Assert.Equal(currentBalance.Value + 20, newBalance.Value);
    }