These are chat archives for Nethereum/Nethereum

21st
Nov 2018
turtlewen
@turtlewen
Nov 21 2018 11:38
@juanfranblanco hi , may i know how should i use nethreum to get the value return from smart contract when i set data?
image.png
my set function in smart contract got returning value
how change this var transactionHash = await setFunction.SendTransactionAsync(senderAddress, new HexBigInteger(900000), null, requestID, result, userID, date, time, remarkORreason);
in to getting of my returning value instead of getting transaction hash
Enigmatic
@EnigmaticUnreal_twitter
Nov 21 2018 11:55

@turtlewen - You're the same turtlewen from TARC?

You can't get the return value from a function which does a state update (transaction). What you could do however is to emit an event and listen for that, or call a separate view function which returns the update.

Depending on the context of your smart contract, the latter might not be feasible (as other state updates may have taken place), so event probably is the much better choice.

turtlewen
@turtlewen
Nov 21 2018 12:16
@EnigmaticUnreal_twitter i see it is impossible to do return in smart contract
for set function
@EnigmaticUnreal_twitter how u know me from tarc??
Enigmatic
@EnigmaticUnreal_twitter
Nov 21 2018 12:22

Yea - Because what we would get in return after sending a transaction is a TransactionReceipt (hence the transaction hash), and the receipt does not make space for arbitrary value returns; Best we could do is to use logs (events).

We spoke a few times before, and you're easy to notice (also noticed you were talking to Zulh the other day at the Geth gitter channel). Are you coming to ETHKL this Friday?

turtlewen
@turtlewen
Nov 21 2018 12:24
@EnigmaticUnreal_twitter i see, where we chat last time?? i mean in what social media ?? facebook??
@EnigmaticUnreal_twitter actually i trying to get the result of submit transaction i want to know is it successful mined or not
Enigmatic
@EnigmaticUnreal_twitter
Nov 21 2018 12:27

If you're using SendTransactionAsync, you could put it into a loop and do a GetTransactionReceipt to see if the transaction has been mined. Or easier, just use SendRequestAndWaitForReceiptAsync.

As long as you could get a receipt, the transaction has been mined.

image.png
image.png
turtlewen
@turtlewen
Nov 21 2018 12:31

so if i mined success for that transaction it will have something return in the receiptHash rite??

if unsuccessful receiptHash will null rite??

Dave Whiffin
@Dave-Whiffin
Nov 21 2018 12:31
@turtlewen To check for success on a TransactionReceipt - check the status

        public static bool Succeeded(this TransactionReceipt receipt)
        {
            return receipt.Status.Value == BigInteger.One;
        }

        public static bool Failed(this TransactionReceipt receipt)
        {
            return !receipt.Succeeded();
        }
Enigmatic
@EnigmaticUnreal_twitter
Nov 21 2018 12:33
Ah Dave is right - If you want to check to see if your transaction passed (transaction completed) or failed (transaction failed, maybe because out of gas or execution error), you can use the status field once you've gotten the receipt returned.
Thanks @Dave-Whiffin :D
turtlewen
@turtlewen
Nov 21 2018 12:36
@Dave-Whiffin i not so understanding the code>< , because me using asp.net. if i put this code under my .cs it will have error in this TransactionReceipt
Dave Whiffin
@Dave-Whiffin
Nov 21 2018 12:38
@turtlewen They are extension methods from a static class. You can use the snippet below in your code to create a success flag.
var success = receipt.Status.Value == BigInteger.One;
turtlewen
@turtlewen
Nov 21 2018 12:45
image.png
@Dave-Whiffin it have error
sorry i just beginner
some function i no idea on it, so might not easy to understand certain function
me explorer by finding example and through debug see what value they return so i only understand the function
explore
Enigmatic
@EnigmaticUnreal_twitter
Nov 21 2018 12:47
It's expecting a receipt... So you could use SendTransactionAndWaitForReceiptAsync instead.
Dave Whiffin
@Dave-Whiffin
Nov 21 2018 12:47
@EnigmaticUnreal_twitter thanks
Enigmatic
@EnigmaticUnreal_twitter
Nov 21 2018 12:48
=D
turtlewen
@turtlewen
Nov 21 2018 12:52
@EnigmaticUnreal_twitter there is a error if i using SendTransactionAndWaitForReceiptAsync to submit transaction , which is intrinsic gas too low'
Enigmatic
@EnigmaticUnreal_twitter
Nov 21 2018 12:55
That would be because the transaction requires additional gas more than what is currently specified.
turtlewen
@turtlewen
Nov 21 2018 12:56
@EnigmaticUnreal_twitter yup, but SendTransactionAndWaitForReceiptAsync not allow me to set HexBigInteger(900000)
Enigmatic
@EnigmaticUnreal_twitter
Nov 21 2018 12:57

So what you could do is to use EstimateGasAsync, or if you'd like to just quickly test and make sure if works, put a larger gas amount.

Something like:

var transactionReceipt = await pushUpdate.SendTransactionAndWaitForReceiptAsync(account.Address,  new HexBigInteger(500000), new HexBigInteger(0));

It's one of the overloads.

image.png
If it still doesn't works, feel free to drop me the code snippet, I can take a look.
turtlewen
@turtlewen
Nov 21 2018 13:06
its work
var transactionHash = await setFunction.SendTransactionAndWaitForReceiptAsync(senderAddress, new HexBigInteger(900000), new HexBigInteger(0), null, requestID, result, userID, date, time, remarkORreason);
        if (transactionHash == null)
            return false;
        else
            return true;
this is my code
var transactionHash = await setFunction.SendTransactionAndWaitForReceiptAsync(senderAddress, new HexBigInteger(900000), new HexBigInteger(0), null, requestID, result, userID, date, time, remarkORreason);
        if (transactionHash == null)
            return false;
        else
            return true;
Enigmatic
@EnigmaticUnreal_twitter
Nov 21 2018 13:09

Awesome. :)

Like what is mentioned by Dave - You might want to take extra care - Since you still can get the receipt even if the transaction gives you an error (transaction executes but revert because of a fault). So a better practice is to check:

if (transactionHash.Status.Value == BigInteger.One)
       return true;
else
      return false;

Something like that.

BigInteger is part of System.Numerics, so you'll need to import that first on the top.
using System.Numerics;
turtlewen
@turtlewen
Nov 21 2018 13:14

if (transactionHash != null && transactionHash.Status.Value == BigInteger.One)
return true;
else
return false;

i change to something like that

if (transactionHash != null && transactionHash.Status.Value == BigInteger.One)
return true;
else
return false;
Enigmatic
@EnigmaticUnreal_twitter
Nov 21 2018 13:19
Cool. Show us your project some day. :)
MANOJKUMARCH
@MANOJKUMARCH
Nov 21 2018 13:55

Hi... I am looking for a command/code to get the coinbase using Nethereum, similar to web3.eth.coinbase w.r.t web3.js.

Could someone please help me here on it

Juan Blanco
@juanfranblanco
Nov 21 2018 14:00
web3.Eth.CoinBase.SendRequestAsync()
mosinms7711
@mosinms7711
Nov 21 2018 14:16
how to get and upload data from/to smart contract using nethereum nuget…???
MANOJKUMARCH
@MANOJKUMARCH
Nov 21 2018 14:19
@juanfranblanco , thank you for the quick response. I have used web3.Eth.CoinBase.SendRequestAsync(), but forgot to add await, now I added and its working fine. Thanks for help
Juan Blanco
@juanfranblanco
Nov 21 2018 14:19
great :)
keepbreath
@keepbreath
Nov 21 2018 14:20
you are great
Juan Blanco
@juanfranblanco
Nov 21 2018 14:27
@mosinms7711
check this doc and see if it helps (it is rather detailed)