These are chat archives for Nethereum/Nethereum

22nd
Mar 2018
Priyank Jani
@PriyankJani_twitter
Mar 22 2018 07:35
@juanfranblanco , https://ropsten.etherscan.io/tx/0x79e81d4fd5acc5e7dd8a9f88d89c7889ef129f5ef32571ce526e1fa9ce31a140 please follow link. I am able to call contract function via Remix but when I try to access from my code that gives me error. "Result of REVERT opcode". If someone can help...
Enigmatic
@EnigmaticUnreal_twitter
Mar 22 2018 08:47

@PriyankJani_twitter - Maybe you could Verify and Publish your smart contract on etherscan so we could have a look. If that's a typical ERC20 off the top of my head you'd need to approve an amount for the sender, before you could call transferFrom.

Based on the transaction history seems that it went from "Contract Deployed" > "Call TransferFrom", so if there's no allowance it'd revert.

Juan Blanco
@juanfranblanco
Mar 22 2018 09:52
@ravinder_123_1_twitter yes correct
Benoit Launay
@blaunay_twitter
Mar 22 2018 12:34
@juanfranblanco this question must have been asked before but I cant find the answer in this long thread ! I understand how to execute a transaction with Nethereum once I can get a user's account (thru his private key or other passwords) but if we want to execute a transaction via a standard browser or a native app, how would a user pass this private key or other passwords / HD wallet ? What are the best practices to integrate with wallets in a standard app (i.e. an app that is not opened via Mist for instance / and not using extension like Metamask that are only valid for Chrome) ?
Chandra Sekhar
@tcsekhar
Mar 22 2018 14:30
Can someone please give me some detail on how to change from localhost geth to public testnet? What should be the url for : Nethereum.Web3.Web3(WhatIsTheURLforRopstenPublicTestNet)
Rickard Öh
@kalasp_twitter
Mar 22 2018 14:37
Hi! Is there a way to compile contracts and get the bytecode and abi using C# and Nethereum?
Chandra Sekhar
@tcsekhar
Mar 22 2018 14:40
You could write code to do that. Its easy, you could just use http://remix.ethereum.org/ to build and then myetherwallet to deploy. Its super easy. Its not like you are going to deploying contracts too many times.
Rickard Öh
@kalasp_twitter
Mar 22 2018 15:14
@tcsekhar Well I am going to deploy them many times, its for a CI build environment. Contracts will deployed each time the build runs. So I need to generate the abi and bytecode programmatically from a .sol. To a private ethereum chain
Chandra Sekhar
@tcsekhar
Mar 22 2018 15:21

@kalasp_twitter have you looked at https://github.com/EthSharp/ethsharp-compiler

I didn't have a need to use it. But something to explore.

Rickard Öh
@kalasp_twitter
Mar 22 2018 15:23
@tcsekhar Deprecated. But since @juanfranblanco have built the solidity compiler for visual studio code there be some way to use it from C#?
Enigmatic
@EnigmaticUnreal_twitter
Mar 22 2018 16:13

@tcsekhar - When you initialise web3 you can use something like infura (https://ropsten.infura.io/<your token here>)

E.g.

Dim iweb3 = New Web3(randomAccount, "https://rinkeby.infura.io/")
Jonathan Sheely
@jsheely
Mar 22 2018 17:35
So I'm having a problem with transactions never getting receipt. Returns null forever
Is that normal?
I'm using Infura as my RPC host.
I'm currently doing a smart contract var transactionId = func.SendTransactionAsync(..) to get the transactionId then doing a var result = GetTransactionReceipt.SendRequestAsync(transactionId) to get the receipt
On ropsten it works 100% of the time. on mainnet transactions never show up on etherscan.io
Chandra Sekhar
@tcsekhar
Mar 22 2018 20:05

I tried the infura with two different testnets:
'
var web3 = new Nethereum.Web3.Web3("https://rinkeby.infura.io/XXXMYKEYXXX");
and
var web3 = new Nethereum.Web3.Web3("https://ropsten.infura.io/XXXMYKEYXXX");

Both just hang while executing this statement. Can you please let me know if there is anything specific I need to do to get this to work?

@EnigmaticUnreal_twitter what is the randomAccount object? How do you create it before connecting to the testnet?
Enigmatic
@EnigmaticUnreal_twitter
Mar 22 2018 20:49

It's 4:40AM here so gonna be brief.

I connected to Web3 Infura with a specific account hence the randomAccount object. You shouldn't have any issues connecting without one. Have you tried connecting without a token?

What I did (in VB) was the below and I was able to get through.

Imports Nethereum.Web3

'initialise web3
Dim web3 As Web3
web3 = New Web3("https://mainnet.infura.io/")
Chandra Sekhar
@tcsekhar
Mar 22 2018 21:29
It wasn't working with the above code for me. Hence I had to do it with a account object declared. But now, I'm stuck at this line:
var account = new ManagedAccount(myContractObj.senderaddress, myContractObj.ethuserpassword);
            myContractObj.web3 = new Nethereum.Geth.Web3Geth(account, myContractObj.ethpooladdress);
            myContractObj.contract = myContractObj.web3.Eth.GetContract(myContractObj.abi, myContractObj.contractaddress);
            var transactionHash = await myContractObj.contract.GetFunction(v_functionName).SendTransactionAsync(myContractObj.senderaddress, new HexBigInteger(900000), null, param);   //>>> THIS LINE IS WHERE IT HANGS
            var receipt = await MineAndGetReceiptAsync(myContractObj.web3, transactionHash);
This line:
myContractObj.contract.GetFunction(v_functionName).SendTransactionAsync(myContractObj.senderaddress, new HexBigInteger(900000), null, param);
it does work with both:
var web3 = new Nethereum.Web3.Web3(account, "https://rinkeby.infura.io/MYTOKEN");
var web3 = new Nethereum.Geth.Web3Geth(account, "https://rinkeby.infura.io/MYTOKEN");
Chandra Sekhar
@tcsekhar
Mar 22 2018 21:35
for some reason, neither of these worked for me:
var web3 = new Nethereum.Web3.Web3("https://rinkeby.infura.io/MYTOKEN");
var web3 = new Nethereum.Geth.Web3Geth("https://rinkeby.infura.io/MYTOKEN");
Jonathan Sheely
@jsheely
Mar 22 2018 21:45
@juanfranblanco Why do you create a new HTTP Client?
private HttpClient GetOrCreateHttpClient()
        {
            lock (_lockObject)
            {
                var timeSinceCreated = DateTime.UtcNow - _httpClientLastCreatedAt;
                if (timeSinceCreated.TotalSeconds > NUMBER_OF_SECONDS_TO_RECREATE_HTTP_CLIENT)
                    CreateNewHttpClient();
                return GetClient();
            }
        }
Chandra Sekhar
@tcsekhar
Mar 22 2018 22:07

This time, I used the sample code from @juanfranblanco : https://github.com/Nethereum/Nethereum/blob/master/src/Nethereum.Tutorials/Nethereum.Tutorials.Core/CallTransactionEvents/CallTranEvents.cs

var senderAddress = myContractObj.senderaddress;
var password = myContractObj.ethuserpassword;
var abi = myContractObj.abi;
var byteCode = myContractObj.bytecode;
var account = new ManagedAccount(senderAddress, password);
var web3 = new Nethereum.Geth.Web3Geth(account, "https://rinkeby.infura.io/XXMYTOKENXX");
web3.Miner.Start.SendRequestAsync(6).GetAwaiter().GetResult();   //>> FAILS HERE

The error message is:

"ExceptionMessage": "Response status code does not indicate success: 405 (Method Not Allowed).",
"ExceptionType": "System.Net.Http.HttpRequestException",
"StackTrace": "   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at Nethereum.JsonRpc.Client.RpcClient.<SendAsync>d__17.MoveNext()"
Juan Blanco
@juanfranblanco
Mar 22 2018 22:15
@tcsekhar you cannot mine a public node
you dont need that
Chandra Sekhar
@tcsekhar
Mar 22 2018 22:15
ok
Juan Blanco
@juanfranblanco
Mar 22 2018 22:16
it is already mining
Chandra Sekhar
@tcsekhar
Mar 22 2018 22:16
I will try without that line
Juan Blanco
@juanfranblanco
Mar 22 2018 22:16
that is to control your local node
but most probably you would not use if you start mining by default
@jsheely to avoid dns issues as .net core does not have the same support as normal .net
Jonathan Sheely
@jsheely
Mar 22 2018 22:18
So without totally understanding this code. What if I'm using the Web3 client as a DI single instance? And I have say 100 requests all going at the same time. Would the 60 second replacement kill one of them?
Juan Blanco
@juanfranblanco
Mar 22 2018 22:18
but maintaining full performance
Chandra Sekhar
@tcsekhar
Mar 22 2018 22:18
@juanfranblanco I removed that line and now its hanging at the last line:
var senderAddress = myContractObj.senderaddress;
var password = myContractObj.ethuserpassword;
var abi = myContractObj.abi;
var byteCode = myContractObj.bytecode;
var account = new ManagedAccount(senderAddress, password);
var web3 = new Nethereum.Geth.Web3Geth(account, myContractObj.ethpooladdress);
var receipt = web3.Eth.DeployContract.SendRequestAndWaitForReceiptAsync(abi, byteCode, senderAddress, new HexBigInteger(900000), null, 7).GetAwaiter().GetResult(); //>> HANGS HERE
Juan Blanco
@juanfranblanco
Mar 22 2018 22:18
@jsheely exactly the opposite
this is to maintain always a single instance and have better performance
Jonathan Sheely
@jsheely
Mar 22 2018 22:20
But if the 60 seconds is up. Won't it get a new one? I don't follow
that is per connection
per request
just follow to GetClient()
there are 2
and you are not going to have a connection open for a request for more than 60 seconds
a single request
that is not related to your transactionReceipt issue
i don't know what it can be
Jonathan Sheely
@jsheely
Mar 22 2018 22:23
This is basically how my queue reader works
sec
Juan Blanco
@juanfranblanco
Mar 22 2018 22:23
i got to go so it is going to be async the answer (long day)
Jonathan Sheely
@jsheely
Mar 22 2018 22:24
No worries. Thanks for your help (in the future)
Night sir
Chandra Sekhar
@tcsekhar
Mar 22 2018 22:29

@jsheely would you be able to help me with my issue. This is might be too basic and easy for you..

I'm trying to interact with a contract deployed on Rinkeby Testnet

I used the example written by @juanfranblanco

var senderAddress = myContractObj.senderaddress;
var password = myContractObj.ethuserpassword;
var abi = myContractObj.abi;
var byteCode = myContractObj.bytecode;
var account = new ManagedAccount(senderAddress, password);
var web3 = new Nethereum.Geth.Web3Geth(account, "https://rinkeby.infura.io/XXMYTOKENXX");
var receipt = web3.Eth.DeployContract.SendRequestAndWaitForReceiptAsync(abi, byteCode, senderAddress, new HexBigInteger(900000), null, 7).GetAwaiter().GetResult(); //>> FAILS HERE

Can you tell me if I'm doing something wrong?

Jonathan Sheely
@jsheely
Mar 22 2018 22:31
I haven't tried rinkeby. Nor have I tried deploying a contract from Nethereum. What does it fail with?
Gas error?
Chandra Sekhar
@tcsekhar
Mar 22 2018 22:31
just hangs
Jonathan Sheely
@jsheely
Mar 22 2018 22:32
So that's how it works
The internal of WaitForReceipt basically does a while(true) loop waiting for the transaction to be complete.
It could take awhile for a contract to be mined.
Chandra Sekhar
@tcsekhar
Mar 22 2018 22:33
I'm not deploying through Nethereum. I just need to interact with my contract. But in the example from @juanfranblanco does the deploy before accessing the function.
Jonathan Sheely
@jsheely
Mar 22 2018 22:34
THen you don't need the byteCode. Just the ABI
You can get access to your function by doing something like this
Client.Eth.GetContract(abi, contractAddress);
where client is your new Web3(account, url)
Chandra Sekhar
@tcsekhar
Mar 22 2018 22:36
ok
what will be the client object?
Jonathan Sheely
@jsheely
Mar 22 2018 22:37
A Web3 object
var contract = new Web3(account,url).Client.Eth.GetContract(abi, contractAddress)
Chandra Sekhar
@tcsekhar
Mar 22 2018 22:40
I am getting IClient does not contain a definintion for Eth and no extension method 'Eth' accepting a first argument of type 'IClient' could be found
 var contract = new Nethereum.Web3.Web3(account, myContractObj.ethpooladdress).Client.>>Eth<<.GetContract(myContractObj.abi, myContractObj.contractaddress);
Jonathan Sheely
@jsheely
Mar 22 2018 22:43
Not sure. It's on my client
Chandra Sekhar
@tcsekhar
Mar 22 2018 22:43
I'm not using a async method - does it require any await?
Jonathan Sheely
@jsheely
Mar 22 2018 22:43
Well, you should be. But that shouldn't effect you as he's put ConfigureAwait(false) on all the methods
But that doesn't explain why Eth is missing off the client. Perhaps you're missing a reference
Chandra Sekhar
@tcsekhar
Mar 22 2018 22:46
its taking the Client as "Nethereum.JsonRPC.Client.IClient" does it seem right?
Jonathan Sheely
@jsheely
Mar 22 2018 22:48
Looks about right
Chandra Sekhar
@tcsekhar
Mar 22 2018 22:48
I have these references:
using Nethereum.Hex.HexTypes;
using Nethereum.RPC.Eth.DTOs;
using Nethereum.Web3.Accounts.Managed;
using Nethereum.Web3;
The Nethereum.Web3 version on my project is v4.0.30319
sorry 2.4.0.0
Jonathan Sheely
@jsheely
Mar 22 2018 22:50
yea same
Chandra Sekhar
@tcsekhar
Mar 22 2018 22:52
@jsheely is there a sample code in Nethereum that you can refer or share which passes in more than one parameter to a contract and gets back a string result
Jonathan Sheely
@jsheely
Mar 22 2018 23:00
The trick to getting multiple properties back is your have to configure an object with some attributes
func.CallDeserializingToObjectAsync<YourObject>
And decorate your object with [FunctionOutput] and put the param order they are in and if the value is indexed. [Parameter("bool", 1)]
Not sure if there are any good examples.
Chandra Sekhar
@tcsekhar
Mar 22 2018 23:01

@jsheely I got the contract to work:

Nethereum.Contracts.Contract contract = new Nethereum.Web3.Web3(account, myContractObj.ethpooladdress).Eth.GetContract(myContractObj.abi, myContractObj.contractaddress);

So from Solidity, I can create a object and send the object as output? And then deserialize it in the C# in Nethereum - you mean?

Jonathan Sheely
@jsheely
Mar 22 2018 23:02
You can't send objects in solidity AFAIK. Only individual return values.
Remember that transactions can't return values. Only Call methods can. Again AFAIK
Chandra Sekhar
@tcsekhar
Mar 22 2018 23:04
I see. Thanks. So for the ParamObj[], I need to send the parameters in the function call as [Parameter("first", "second",3)]
Jonathan Sheely
@jsheely
Mar 22 2018 23:04
I was showing for the output
Chandra Sekhar
@tcsekhar
Mar 22 2018 23:04
ok
Jonathan Sheely
@jsheely
Mar 22 2018 23:04
For the input I just pass them in. But it might be possible do serialize it that way as well
Chandra Sekhar
@tcsekhar
Mar 22 2018 23:04
for the input - if solidity has 3 parameters, how do I pass
Jonathan Sheely
@jsheely
Mar 22 2018 23:04
Haven't tried
Chandra Sekhar
@tcsekhar
Mar 22 2018 23:05
ok
Jonathan Sheely
@jsheely
Mar 22 2018 23:05
I just pass them in at the end of the Param array
Chandra Sekhar
@tcsekhar
Mar 22 2018 23:05

Thank you so much @jsheely

You saved a lot of time for me

Jonathan Sheely
@jsheely
Mar 22 2018 23:06
In my case it's like SendTransactionAsync(account, gas null, null,param1,param2,param3)
No prob
Chandra Sekhar
@tcsekhar
Mar 22 2018 23:06
oh thats easy. Thanks a lot again!
Chandra Sekhar
@tcsekhar
Mar 22 2018 23:13

I thought I was all done so quickly :(

Its now hanging at the last line again:

var senderAddress = myContractObj.senderaddress;
var password = myContractObj.ethuserpassword;
var abi = myContractObj.abi;
var byteCode = myContractObj.bytecode;
var account = new ManagedAccount(senderAddress, password);
var web3 = new Nethereum.Geth.Web3Geth(account, myContractObj.ethpooladdress);
Nethereum.Contracts.Function function = new Nethereum.Web3.Web3(account, myContractObj.ethpooladdress).Eth.GetContract(myContractObj.abi, myContractObj.contractaddress).GetFunction("storeHash");
// HANGS AT THE NEXT LINE BELOW
var transactionHash = function.SendTransactionAsync(myContractObj.senderaddress, new HexBigInteger(9000000), null, "Test", "Something", "1/1/2018").GetAwaiter().GetResult();
Chandra Sekhar
@tcsekhar
Mar 22 2018 23:20

Just not to confuse, here are the 3 lines of code - the 3rd line fails:

var account = new ManagedAccount(myContractObj.senderaddress, myContractObj.ethuserpassword);
Nethereum.Contracts.Function function = new Nethereum.Web3.Web3(account, "https://rinkeby.infura.io/XXMYTOKENXX").Eth.GetContract(myContractObj.abi, myContractObj.contractaddress).GetFunction("storeHash");
var transactionHash = function.SendTransactionAsync(myContractObj.senderaddress, new HexBigInteger(9000000), null, "Test", "Something", "1/1/2018").GetAwaiter().GetResult();

Here is the Solidity code:

function storeHash(string inHashString, string inDescription, string inSubmitDate) public pure returns (uint) {    
        ethaccount = msg.sender;
        computedhash = inHashString;
        description = inDescription;
        submitteddatetime = inSubmitDate;
        trndatetime = now;
        return now;
    }

This contract is published at Rinkleby Testnet:

https://rinkeby.etherscan.io/address/0xd9834052f59db82d815bb1731867d0ca0a3f02d3

I can't seem to be able to get past calling a Solidity function from Nethereum.

If rinkleby is the problem, can someone please suggest me a different public test net I could use with Nethereum and how?