These are chat archives for Nethereum/Nethereum

29th
Mar 2018
Nhat Nguyen
@tieudieudu
Mar 29 2018 04:17 UTC

Hello everybody, I'm trying to invoke smart contract by Nethereum. How to call payable function in smart contract? This is my payable function in smart contract:

function buy() payable public {
        uint256 amount = msg.value / _buyPrice;
        _transfer(owner, msg.sender, amount);
    }

Thanks.

Enigmatic
@EnigmaticUnreal_twitter
Mar 29 2018 06:37 UTC

@quangnhat91 Just send some ethers to the contract will do.

Something like:

txID = Await web3.TransactionManager.SendTransactionAsync(sender, contractaddress, amt)
receiptHash = Await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txID)
You might want to bump up gas amount in case the default gas sent isn't enough to execute the payable function.
Nhat Nguyen
@tieudieudu
Mar 29 2018 06:40 UTC
Thanks @EnigmaticUnreal_twitter. Do we have any way to estimate gas fee before execute the transaction?

one more thing, as I know send some ethers to the contract just support the unname payable function, like:

function () payable { .. }

in mine have name buy

Enigmatic
@EnigmaticUnreal_twitter
Mar 29 2018 06:43 UTC

Try using TransactionManager.EstimateGasAsync

Oh - Sorry - Now I see.
In this case you'll GetFunction("buy"), create a SendTransactionAndWaitForReceiptAsync with a value. There are overloads for that.

buyFunction = contract.GetFunction("buy")
Await buyFunction.SendTransactionAndWaitForReceiptAsync(from, gas, value)
Something like this.
Nhat Nguyen
@tieudieudu
Mar 29 2018 06:55 UTC
Thank you :)
Jonathan Sheely
@jsheely
Mar 29 2018 13:56 UTC
So am I really the only one getting transactions that are disappearing and not even showing up as pending? Seems like there is a whole issue logged about it. ethereum/go-ethereum#14669 Just curious what you folks currently do to handle it
Juan Blanco
@juanfranblanco
Mar 29 2018 13:58 UTC
I have not encountered those issues
what node are you pointing at?
what chain?
Jonathan Sheely
@jsheely
Mar 29 2018 14:33 UTC
Mainnet, Infura
I don't see these issues on Ropsten. Just mainnet
Juan Blanco
@juanfranblanco
Mar 29 2018 14:34 UTC
ok ill let them know
Jonathan Sheely
@jsheely
Mar 29 2018 14:35 UTC
Okay. so this is abnormal then. So I should be expecting "typically" that if I do someFunc.SendTransactionAsync() with a reasonably high gas price. It should show up as pending at least and actually be mined.
Because right now I get a transactionId back from that function. But it's never seen on the blockchain, pending or otherwise.
Juan Blanco
@juanfranblanco
Mar 29 2018 14:38 UTC
Ok Ill let you know what is the answer
Jonathan Sheely
@jsheely
Mar 29 2018 16:02 UTC
I'm speculating right now, watching wireshark, but I think I'm seeing a bunch of results back from Infura with a result=0x0000000000000000000000000000000000000000000000000000000000000000 It looks like Nethereum is automatically retrying these though
Juan Blanco
@juanfranblanco
Mar 29 2018 16:03 UTC
well that will be the polling for the receipt?
is that preceded by a json
eth_getTransactionReceipt
Jonathan Sheely
@jsheely
Mar 29 2018 16:03 UTC
Actually I lied. I clicked the wrong transaction. It was an eth_call
Juan Blanco
@juanfranblanco
Mar 29 2018 16:03 UTC
ah
Jonathan Sheely
@jsheely
Mar 29 2018 16:06 UTC
I basically have like a 90% failure right right now. It's weird. If I fire 1 transaction and wait for each receipt it seems to work fine. But as soon I let me loop run multiple concurrent. They disappear
I get a transaction back from each SendTransactionAsync() though so you'd think that it would be on the network
Juan Blanco
@juanfranblanco
Mar 29 2018 16:07 UTC
yes they should be queued
Jonathan Sheely
@jsheely
Mar 29 2018 16:07 UTC
Yea it's been days and they don't even show up on etherscan at all.
Juan Blanco
@juanfranblanco
Mar 29 2018 16:08 UTC
but you can resend again using the same address?
and nonce?
Jonathan Sheely
@jsheely
Mar 29 2018 16:09 UTC
So that I haven't tried yet. Trying to figure out. Since I don't create the TransactionInput. I just pass all the params into SendTransactionAsync() and let it do it
But that's what I'm thinking of changing to since I'm having issues. I'm just not sure how long to wait
Juan Blanco
@juanfranblanco
Mar 29 2018 16:10 UTC
one thing to check is to see the transaction count
as the nonces are driven by that
so if your transaction count (blockParameter.pending)
does not increase
your transaction is not in the pending
also make sure that you if you are running in parallel you need to keep track of your nonces
or let nethereum do that for you
Jonathan Sheely
@jsheely
Mar 29 2018 16:12 UTC
Yea I was letting Nethereum do it. But not sure it's working as I expect
So in theory that shouldn't be any issues running multiple threads and having Nethereum generating the nonces?
for the different scenarios
Jonathan Sheely
@jsheely
Mar 29 2018 16:22 UTC
I jumped into the deep end right away with Nethereum and now I'm swimming back to shore learning about things like Nonces =)
Juan Blanco
@juanfranblanco
Mar 29 2018 16:24 UTC
sometimes is better
try to get something done, and once you have a very good understanding all the pieces complement it with all the other details
Jonathan Sheely
@jsheely
Mar 29 2018 16:27 UTC
So let me ask you this. In the scenario I'm having. What do you suggest I do? Manage my own Nonces? How should I verify that the transaction is in the pool
Juan Blanco
@juanfranblanco
Mar 29 2018 16:27 UTC
well i don't know exactly what you are doing
but if you have a single account address sending many transactions in a queue
Jonathan Sheely
@jsheely
Mar 29 2018 16:28 UTC
Yep that's basically it
Juan Blanco
@juanfranblanco
Mar 29 2018 16:28 UTC
each transaction needs its own unique nonce (in order)
so you can 1 have a managed queue
so 1 transaction at a time
or 2 multiple threaded with a nonce provider as in the first sample
on the link I sent you
Jonathan Sheely
@jsheely
Mar 29 2018 16:29 UTC
Okay. So if multi threaded then I need a nonce provider. Nethereum isn't going to do that for me you're saying
Juan Blanco
@juanfranblanco
Mar 29 2018 16:29 UTC
if you cannot cotrol or managed the queue
well you have that the nonce provider already
Jonathan Sheely
@jsheely
Mar 29 2018 16:30 UTC
I can control and manage it. I just wanted to be able to rapidly blast out 100 transactions at the same time
Juan Blanco
@juanfranblanco
Mar 29 2018 16:30 UTC
I have tested it with 1000s
and is ok
obviously you have the limits of the node you are connecting
Jonathan Sheely
@jsheely
Mar 29 2018 16:31 UTC
Yea
Juan Blanco
@juanfranblanco
Mar 29 2018 16:31 UTC
so as per the sample if you have that singleton in memory you are fine
Jonathan Sheely
@jsheely
Mar 29 2018 16:32 UTC
Sorry to repeat this but I'm getting confused.
var nonceProvider = new InMemoryNonceService(senderAddress, client);
Juan Blanco
@juanfranblanco
Mar 29 2018 16:32 UTC
yes that one
keep that as a singleton
Jonathan Sheely
@jsheely
Mar 29 2018 16:33 UTC
Right, but you're saying if I'm running multi threaded and not keeping that. I'll have a problem
Juan Blanco
@juanfranblanco
Mar 29 2018 16:33 UTC
what this does it keeps a counter of your nonces but also validates the count with your pending transactions
Jonathan Sheely
@jsheely
Mar 29 2018 16:33 UTC
Nethereum isn't doing that internally right now ?
Juan Blanco
@juanfranblanco
Mar 29 2018 16:33 UTC
yes it does
if you keep a single instance of web3
Jonathan Sheely
@jsheely
Mar 29 2018 16:34 UTC
I do
Juan Blanco
@juanfranblanco
Mar 29 2018 16:34 UTC
for all the threads
Jonathan Sheely
@jsheely
Mar 29 2018 16:35 UTC
In theory, yes it should be the same instance. It's DI injected
Should be the same instance
Using AutoFac as my injector. doing
builder.RegisterType<Blockchain>()
                .SingleInstance()
                .AsImplementedInterfaces();
Where Blockchain is my class that contains Web3
Juan Blanco
@juanfranblanco
Mar 29 2018 16:36 UTC
I guess that should be fine
Jonathan Sheely
@jsheely
Mar 29 2018 16:36 UTC
Yea "in theory"
Juan Blanco
@juanfranblanco
Mar 29 2018 16:37 UTC
what manages that "service"
or api
Jonathan Sheely
@jsheely
Mar 29 2018 16:37 UTC
I process my queue using Rx Observable.Interval(TimeSpan.FromSeconds(1)).ObserveOn(Scheduler.NewThread).Select(...)
Juan Blanco
@juanfranblanco
Mar 29 2018 16:39 UTC
yes in theory should not be a problem
Jonathan Sheely
@jsheely
Mar 29 2018 16:40 UTC
Welp, back to the drawing board I guess.
Juan Blanco
@juanfranblanco
Mar 29 2018 16:40 UTC
my suggestion will be to test it
without
DI or RX
Jonathan Sheely
@jsheely
Mar 29 2018 16:41 UTC
Yea good idea
Juan Blanco
@juanfranblanco
Mar 29 2018 16:41 UTC
1 step at a time
Jonathan Sheely
@jsheely
Mar 29 2018 16:41 UTC
Well it works if I do each transaction 1 at a time
And wait for the receipt for each one. It just takes FOREVER.
Juan Blanco
@juanfranblanco
Mar 29 2018 16:46 UTC
oh yes for that scenario it does not make any sense to do it that way
you will be like you said forever
hence on that sample i get a concurrent dictionary of all the txn hashes
and then poll for each receipt
in parallel
Jonathan Sheely
@jsheely
Mar 29 2018 16:52 UTC
Yea that is probably better. Send each transaction 1 by 1 (instead of concurrently) then just concurrently read the receipt. Good idea
Juan Blanco
@juanfranblanco
Mar 29 2018 16:53 UTC
oh you can do it concurrently
send the transactions
keeping the nonce count in memory
which is what the in memory nonce provider / service does
Jonathan Sheely
@jsheely
Mar 29 2018 16:54 UTC
Right, So I shouldn't have to worry about keeping the nonce count in memory. As long as Web3 client is the same then Nethereum is doing it for me
Juan Blanco
@juanfranblanco
Mar 29 2018 16:55 UTC
yes
Jonathan Sheely
@jsheely
Mar 29 2018 17:17 UTC
If getTransactionCount comes back with the same value before sending another transaction. That's bad right
Sent 10 transactions. And the value was result=0xa97 every time
Jonathan Sheely
@jsheely
Mar 29 2018 17:30 UTC
I've always wondered. What is the "value" param in the TransactionInput? I see gas, gasPrice and value.
Juan Blanco
@juanfranblanco
Mar 29 2018 17:31 UTC
value is the amount of ether you sent
in wei
Jonathan Sheely
@jsheely
Mar 29 2018 17:31 UTC
Oh
Juan Blanco
@juanfranblanco
Mar 29 2018 17:31 UTC
yes getTransactionCount will be the same if not including pending as a blockParameter
Jonathan Sheely
@jsheely
Mar 29 2018 17:31 UTC
Ahh
Juan Blanco
@juanfranblanco
Mar 29 2018 17:32 UTC
although it might not be yet in the pending queue
when multithreading etc.. due to racing
this is why we keep our internal counter
Jonathan Sheely
@jsheely
Mar 29 2018 17:32 UTC
Ahh
EKostan
@EKostan
Mar 29 2018 20:27 UTC
hello, how I can get latestBlockNumber if I execute BlockParameter.CreateLatest() then BlockNumber = null
I need real last block number in this time
EKostan
@EKostan
Mar 29 2018 20:41 UTC

ok sorry I find it

var lastBlockNumberBigInt = await _blockChainProvider.Web3.Eth.Blocks.GetBlockNumber.SendRequestAsync();