These are chat archives for Nethereum/Nethereum

13th
Dec 2018
Juan Blanco
@juanfranblanco
Dec 13 2018 00:26
You cannot use the personal RPC request with infura
They are designed for your local node
@AhmedAli202020 thanks I'll have a look tomorrow
msharp19
@msharp19
Dec 13 2018 04:02
ahhh thanks Juan!
MANOJKUMARCH
@MANOJKUMARCH
Dec 13 2018 14:06

Hi, using Visual studio code, I am able to generate the code for smart contract written in smart contract. Using the contract handler, I am able to call the functions of the contract that are available in service.cs file.
However I did not find anything to call or get details from events.
But in https://nethereum.readthedocs.io/en/latest/contracts/calling-transactions-events/ I see we can get details from events using the contract variable.

My doubt is that, do I need to again pass the abi and create a contract variable, or do we have a process to call/get details of the events directly from the code generated using visual studio code.

Dave Whiffin
@Dave-Whiffin
Dec 13 2018 14:51
@MANOJKUMARCH Below is a code sample. It uses the code generated classes to deploy a contract, invoke transactions and read logs. The function is "Publish" and the event is "OnPublish".
using Contracts.PublishTest;
using Contracts.PublishTest.ContractDefinition;
using Nethereum.RPC.Eth.DTOs;
using Nethereum.Web3;
using Nethereum.Web3.Accounts;
using System;
using System.Threading.Tasks;
using System.Linq;
using System.Threading;
using Nethereum.Contracts;
using System.Collections.Generic;
using Nethereum.Hex.HexTypes;
using Nethereum.JsonRpc.Client;
using Nethereum.Web3.Accounts.Managed;
using Nethereum.Contracts.Extensions;

namespace NethereumSamples
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var web3 = new Web3("http://localhost:8545");

            var accounts = await web3.Eth.Accounts.SendRequestAsync();
            var account = new ManagedAccount(accounts[0], "password");

            web3 = new Web3(account, "http://localhost:8545");

            const string retailer = "0x12890d2cce102216644c59dae5baed380d84830d"; // just a randomly generated address

            var service = await PublishTestService.DeployContractAndGetServiceAsync(web3, new PublishTestDeployment());

            var onPublishEvent = service.ContractHandler.GetEvent<OnPublishEventDTO>();

            var filterInput = onPublishEvent.CreateFilterInput(new object[]{retailer});

            var filterId = await onPublishEvent.CreateFilterAsync(filterInput);

            var receipt1 = await service.PublishRequestAndWaitForReceiptAsync(new PublishFunction
            {
                Retailer = retailer,
                StdPromoJson = "Promo20181210_1"
            });

            await GetAndPrintLogs(filterId);

            var receipt2 = await service.PublishRequestAndWaitForReceiptAsync(new PublishFunction
            {
                Retailer = retailer,
                StdPromoJson = "Promo20181210_2"
            });

            await GetAndPrintLogs(filterId);

            Console.ReadLine();

        }

        static async Task GetAndPrintLogs(HexBigInteger filterId)
        {
            var web3 = new Web3("http://localhost:8545");
            var onPublishEvent = new Event<OnPublishEventDTO>(web3.Client);
            var logs = await onPublishEvent.GetFilterChanges(filterId);
            Console.WriteLine($"txns: {logs.Count()}");
            foreach(var log in logs)
            {
                Console.WriteLine($"tx: {log.Log.TransactionHash}");
                Console.WriteLine($"Retailer: {log.Event.Retailer}");
                Console.WriteLine($"StdPromoJson: {log.Event.StdPromoJson}");

                var transaction = await web3.Eth.Transactions.GetTransactionByHash.SendRequestAsync(log.Log.TransactionHash);
                var functionInput = transaction.DecodeTransactionToFunctionMessage<PublishFunction>(); //Nethereum.RPC.Eth.DTOs.Transaction

                Console.WriteLine($"Function Input: Retailer: {functionInput.Retailer}");
                Console.WriteLine($"Function Input: StdPromoJson: {functionInput.StdPromoJson}");
            }
        }


    }
}
Dave Whiffin
@Dave-Whiffin
Dec 13 2018 15:08
@AhmedAli202020 Hi - I'll take a look at this for you if you want. Could you possibly send your solidity contract or perhaps a snippet of the events? Also - what version of Nethereum are you using?
MANOJKUMARCH
@MANOJKUMARCH
Dec 13 2018 15:12
@Dave-Whiffin , Thanks Dave, I am looking into the sample code and trying to understand, I will get back
Raúl
@rsantirso
Dec 13 2018 16:14
Hi, folks! I think I have a newbie doubt: I have checked Nethereum code and conclude that after awaiting SendTransactionAndWaitForReceiptAsync and getting the receipt, the snapshot of my ethereum network is such that the transaction was mined and the blockchain updated. My doubt: Is the blockchain copy of the node that has returned me the receipt updated? Could it be possible that a call (not a transaction) executed right after the transaction is executed against an obsolete blockchain, that is, a blockchain where the block where the transaction was mined is not present?
Roy
@Shammah
Dec 13 2018 16:19
I'm not sure I understand your question. If you receive a receipt from a given client for a given transaction, that transaction will be done, 100% complete on that given client
You only receive a receipt if the transaction was successful, and when a transaction was successful, the entire code invocation has been run and completed until end.
Receipts contain transaction outcome, and that can only be send when the transaction has been processed fully
Dave Whiffin
@Dave-Whiffin
Dec 13 2018 16:34
I would add that you should check the status on the receipt (e.g. receipt.Status) It is possible to receive a receipt for a transaction where an error has occurred - so check the receipt.Status equals 1.
Roy
@Shammah
Dec 13 2018 16:41
Oh, right, while atomic, they can still fail, or run out of gas ;)
Raúl
@rsantirso
Dec 13 2018 17:32
Status is OK. The fact is that whether I stress my geth client with a bunch of transactions, sometimes a callasync to a public view of a deployed contract doesn't return because a 'requires' is failing when it must not. And I'm sure that it must not because after waiting a few seconds, a retry on the callasync is successful.
Dave Whiffin
@Dave-Whiffin
Dec 13 2018 17:35
@rsantirso Are you processing in parallel - or single threaded?
Roy
@Shammah
Dec 13 2018 17:36
That does indeed sound odd
Raúl
@rsantirso
Dec 13 2018 17:37
I'm awaiting both functions. CallAsync is awaited after return from the asynk Task function that wraps the SendTransactionAndWaitForReceiptAsync one.
Dave Whiffin
@Dave-Whiffin
Dec 13 2018 17:38
@rsantirso How are you stressing the geth client though? Are you attempting many transactions in parallel? If so - you can run into Nonce issues.
Raúl
@rsantirso
Dec 13 2018 17:38
Yep, @Shammah , I'm frankly annoyed :S
Roy
@Shammah
Dec 13 2018 17:39
Wouldn't he then be getting an error status for that particular transaction?
Dave Whiffin
@Dave-Whiffin
Dec 13 2018 17:41
I think it's best to fully understand the scenario first. Snapshots of solidity contracts and c# would be helpful to diagnose.
Raúl
@rsantirso
Dec 13 2018 17:42
Yes, @Dave-Whiffin , I'm launching a batch of tests in parallel. The accounts calling the transaction are shared between them and, in fact, sometimes I get an rpc exception about 'already known transaction' (that's the message, more or less).
but that rpc exception is expected in my scenario.
Dave Whiffin
@Dave-Whiffin
Dec 13 2018 17:43
Does the same thing occur if you do not share accounts?
Apologies - I need to sign off now - but I'll try and help later on this evening if you still need it.
Roy
@Shammah
Dec 13 2018 17:44
Same here
Raúl
@rsantirso
Dec 13 2018 17:44
I haven't tried that.
Don't worry, folks, I'm at home and can't access the code.
I will try tomorrow and share any news. Thanks for your help!
Devedse
@devedse
Dec 13 2018 20:32
@juanfranblanco , and the rest, I'm trying to call a function that returns (uint256[] blah1, uint256[] blah2)
I created an object:
public class TheObject
{
        [Parameter("uint256[]", "blah1", 1)]
        public BigInteger[] Blah1 { get; set; }

        [Parameter("uint256[]", "blah2", 2)]
        public BigInteger[] Blah2 { get; set; }
}
However if I now call await function.CallDeserializingToObjectAsync<TheObject>();
I get System.MissingMethodException: 'No parameterless constructor defined for this object.'
Which is probably because of the uint256[] array
Any idea how to fix this?
Devedse
@devedse
Dec 13 2018 20:46
Ah I made them List<BigInteger> and it works :)
Dave Whiffin
@Dave-Whiffin
Dec 13 2018 21:02
@devedse I was just about to suggest that. Sorry for the delay. It’s often worth using the code generator either from vs code or the cli as it will generate compatible DTO’s for your contract which removes the guesswork. https://nethereum.readthedocs.io/en/latest/nethereum-code-generation/