These are chat archives for Nethereum/Nethereum

23rd
Mar 2018
Jose
@iGunSlingeRv2_twitter
Mar 23 2018 01:03

Hi everyone! I am having an issue getting my account balance using EthGetBalanceUnityRequest in Unity. It works fine in the Editor but on mobile it never grabs it. I am using xcode to build on the iphone. Not sure if there is a setting I need to set somewhere in xcode or project settings in Unity.

This is the error that pops out of xcode:

JsonException: No parameterless constructor defined for 'Nethereum.RPC.Eth.DTOs.BlockParameterJsonConverter'.
  at Newtonsoft.Json.Serialization.JsonTypeReflector+<>c__DisplayClass20_0.<GetCreator>b__0 (System.Object[] parameters) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonTypeReflector.GetJsonConverter (System.Object attributeProvider) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract (Newtonsoft.Json.Serialization.JsonContract contract) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract (System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System.Type type) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList (Newtonsoft.Json.JsonWriter writer, IEnumerable values, Newtonsoft.Json.Serialization.JsonArrayContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeConvertable (Newtonsoft.Json.JsonWriter writer, Newtonsoft.Json.JsonConverter converter, System.Object value, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonConvert.SerializeObjectInternal (System.Object value, System.Type type, Newtonsoft.Json.JsonSerializer jsonSerializer) [0x00000] in <filename unknown>:0 
  at Nethereum.JsonRpc.UnityClient.UnityRpcClient`1+<SendRequest>c__Iterator0[TResult].MoveNext () [0x00000] in <filename unknown>:0
Rethrow as JsonException: Error creating 'Nethereum.RPC.Eth.DTOs.BlockParameterJsonConverter'.
  at Newtonsoft.Json.Serialization.JsonTypeReflector+<>c__DisplayClass20_0.<GetCreator>b__0 (System.Object[] parameters) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonTypeReflector.GetJsonConverter (System.Object attributeProvider) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract (Newtonsoft.Json.Serialization.JsonContract contract) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract (System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System.Type type) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList (Newtonsoft.Json.JsonWriter writer, IEnumerable values, Newtonsoft.Json.Serialization.JsonArrayContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeConvertable (Newtonsoft.Json.JsonWriter writer, Newtonsoft.Json.JsonConverter converter, System.Object value, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonConvert.SerializeObjectInternal (System.Object value, System.Type type, Newtonsoft.Json.JsonSerializer jsonSerializer) [0x00000] in <filename unknown>:0 
  at Nethereum.JsonRpc.UnityClient.UnityRpcClient`1+<SendRequest>c__Iterator0[TResult].MoveNext () [0x00000] in <filename unknown>:0
This is the function to get the balance:
EthGetBalanceUnityRequest balanceRequest = new EthGetBalanceUnityRequest (url);
        yield return balanceRequest.SendRequest (address, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest());

        if (balanceRequest.Exception == null) 
        {
            BigInteger balance = balanceRequest.Result.Value;
            decimal dbalance = Nethereum.Util.UnitConversion.Convert.FromWei (balance, Nethereum.Util.UnitConversion.EthUnit.Ether);

            callback.Invoke(double.Parse(dbalance.ToString ("0.####")));
        } 
        else 
        {
            callback.Invoke(0.0);
        }
Chandra Sekhar
@tcsekhar
Mar 23 2018 02:10

I deployed my contract to Ropsten test network, and modified my code to use Ropsten.infura url with token. Now, it doesn't hang. But it errors out on execution of the 3rd line below:

var account = new ManagedAccount(myContractObj.senderaddress, myContractObj.ethuserpassword);
Nethereum.Contracts.Function function = new Nethereum.Web3.Web3(account, "https://ropstin.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 error message:

"ExceptionMessage":"Response status code does not indicate success: 405 (Method Not Allowed).","ExceptionType":"System.Net.Http.HttpRequestException","StackTrace":"   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()\r\n   at Nethereum.JsonRpc.Client.RpcClient.<SendAsync>d__17.MoveNext()"

Any help with regards to how to call a Solidity function deployed on any Ethereum PUBLIC Test network from within C# code using Nethereum would be really nice. I'm sure almost everyone here who is using Nethereum would have done this before. A sample code of how to call would be of really great help.

Enigmatic
@EnigmaticUnreal_twitter
Mar 23 2018 03:34

@tcsekhar - Looks like your issue isn't so much on the Nethereum side. If your contract is the storeHash contract - Then you'll need to remove pure since you're making a state change.

You can review the contract I have published here: https://rinkeby.etherscan.io/address/0x6102f1533f6f3aea37cf80212258704f7a73919b#code

A quick and dirty test code (VB though, haven't had my coffee yet for C#) I have cooked up to upload data to the contract:

Dim privateKey As New Nethereum.Signer.EthECKey("<your private key>")
Dim account = New Nethereum.Web3.Accounts.Account(privateKey)

 ' ABI of the deployed contract
Dim abi = "<too long to paste>"
Dim iweb3 = New Web3(account, "https://rinkeby.infura.io/")

' contract address - Get contract
Dim tokenContractAddress = "0x6102f1533f6F3AeA37CF80212258704F7a73919B"
Dim tokencontract = iweb3.Eth.GetContract(abi, tokenContractAddress)

Dim gas As New HexBigInteger(200000)
Dim value As New HexBigInteger(0)

Dim storeHash = tokencontract.GetFunction("execStoreHash")
Dim transactionHash = Await storeHash.SendTransactionAndWaitForReceiptAsync(account.Address, gas, value, , "0x01234567890", "Something", "1/1/2018")
MsgBox("Transaction included in block number: " & transactionHash.BlockNumber.Value.ToString & ", transaction hash: " & transactionHash.TransactionHash.ToString)
If you see the "Read Smart Contract" tab you'll see the data being uploaded, corresponding to txHash 0xdb32769f866ae514a7e5682b35c5151ffdc402851b6b7758b206367c809509a7
Hope this helps and all the best.
Enigmatic
@EnigmaticUnreal_twitter
Mar 23 2018 03:45
Oh btw yes it takes a while for your transaction to get sent and mined (SendTransactiomAndWaitForReceipt).
Rickard Öh
@kalasp_twitter
Mar 23 2018 07:04

Hi the code below works perfectly with Ganache but when trying the same code to an azure hosted ethereum private blockchain the second row always returns NULL (receipt = null).
The accounts used in Ganache and Azure both exists and have ether.
Any idea why that is?

var transactionHash = await _web3.Eth.DeployContract.SendRequestAsync(ethContractModel.Abi, ethContractModel.ByteCode, ethContractModel.Creator.SenderAddress, gas, valueAmount,......);
var receipt = await _web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);

Tried with both Nethereum.Portable 2.2 and 2.4.

Enigmatic
@EnigmaticUnreal_twitter
Mar 23 2018 07:27

@kalasp_twitter

Ganache will confirm your transaction immediately and automines; Not sure about the Azure hosted Ethereum instance though (haven't worked on one) - Could you do a loop as long as Receipt == NULL, followed by a Thread.Sleep for a couple seconds, to see if the transaction receipt pops up after a while?

You could also fire your code on a public testnet like Rinkeby or Ropsten to see if it works all fine - Likewise requiring some waiting for the transaction to be mined so a receipt is returned.

Feel free to correct me if I have made wrong assumptions on the Azure bit.

Benoit Launay
@blaunay_twitter
Mar 23 2018 08:50
re asking this question as someone must know the answer : 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) ?
sumathyvenugopal
@sumathyvenugopal
Mar 23 2018 10:37
Hi,Could someone please send a sample working C# code for creating KeyVaultClient object in MAC OS ( Visual studio 2017 is the Ide, I am using)?
Rickard Öh
@kalasp_twitter
Mar 23 2018 12:09
@EnigmaticUnreal_twitter Oh ok, but shouldnt the await "wait" for the receipt?
Rickard Öh
@kalasp_twitter
Mar 23 2018 12:26
@EnigmaticUnreal_twitter I used the SendRequestAndWaitForReceiptAsync and got it working with Azure. Your solution would have worked as well. Thanks
Chandra Sekhar
@tcsekhar
Mar 23 2018 12:44
@EnigmaticUnreal_twitter Thank you so much!! I will try this
Chandra Sekhar
@tcsekhar
Mar 23 2018 14:34

@EnigmaticUnreal_twitter I tried your suggestion - removed the pure and deployed my contract and tried through different test networks. I still get "Method not allowed" error 405 message from infura.

Here is the entire contract:

pragma solidity ^0.4.14;

contract MySmartContract {
    address internal ethaccount;
    string internal computedhash;
    string internal description;
    string internal submitteddatetime;
    uint internal trndatetime;

    function storeHash(string inHashString, string inDescription, string inSubmitDate) public  returns (uint) {    
        ethaccount = msg.sender;
        computedhash = inHashString;
        description = inDescription;
        submitteddatetime = inSubmitDate;
        trndatetime = now;
        return now;
    }
    function getStoredHash() public view returns(string) {
        return computedhash;
    }
    function getStoredDescription() public view returns(string) {
        return description;
    }
    function getSubmittedDate() public view returns(string) {
        return submitteddatetime;
    }
    function getTransactionDate() public view returns(string) {
        return uintToString(trndatetime);
    }
    function uintToString(uint v) private pure returns (string str) {
        uint maxlength = 100;
        bytes memory reversed = new bytes(maxlength);
        uint i = 0;
        while (v != 0) {
            uint remainder = v % 10;
            v = v / 10;
            reversed[i++] = byte(48 + remainder);
        }
        bytes memory s = new bytes(i + 1);
        for (uint j = 0; j <= i; j++) {
            s[j] = reversed[i - j];
        }
        str = string(s);
    }
}

Here is the code I'm calling in C#:

            var account = new ManagedAccount(myContractObj.senderaddress, myContractObj.ethuserpassword);
            Nethereum.Contracts.Function function = new Nethereum.Web3.Web3(account, myContractObj.ethpooladdress).Eth.GetContract(myContractObj.abi, myContractObj.contractaddress).GetFunction("storeHash");
            var transactionHash = function.SendTransactionAndWaitForReceiptAsync(myContractObj.senderaddress, new HexBigInteger(9000000), new HexBigInteger(0), null , "Test", "Something", "1/1/2018").GetAwaiter().GetResult();

It fails when calling the "storeHash" function with "Method not allowed 405 error"

{"Message":"An error has occurred.","ExceptionMessage":"Response status code does not indicate success: 405 (Method Not Allowed).","ExceptionType":"System.Net.Http.HttpRequestException"
Chandra Sekhar
@tcsekhar
Mar 23 2018 14:42

I even tried without a return in the storeHash function

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

I get the same error message even then. Not sure what I'm doing wrong.

Juan Blanco
@juanfranblanco
Mar 23 2018 14:48
@tcsekhar you cannot use a managed account to connect to a public chain
for a simple interaction with contracts
Chandra Sekhar
@tcsekhar
Mar 23 2018 15:29
Sorry, I didn't know that. I am going to try the same with a keystore file and password for creating the web3 object.
Thank you again.
Juan Blanco
@juanfranblanco
Mar 23 2018 15:29
no need to apologise
you can easily get the private key (string) from the keystore if you want
and user directly
or if you have a 12 word seed from metamask
you can use the HD wallet
Chandra Sekhar
@tcsekhar
Mar 23 2018 17:06
I used the private keystring. Now it just hangs for ever - (had waited for 15 mins)
            var account = new Nethereum.Web3.Accounts.Account("b3XXXXXXXXXPRIVATEKEYXXXXX7b7");
            Nethereum.Contracts.Function function = new Nethereum.Web3.Web3(account, "https://ropsten.infura.io/XXMYTOKEN").Eth.GetContract(myContractObj.abi, myContractObj.contractaddress).GetFunction("storeHash");
            var transactionHash = function.SendTransactionAndWaitForReceiptAsync(myContractObj.senderaddress, new HexBigInteger(9000000), new HexBigInteger(0), null , "Test", "Something", "1/1/2018").GetAwaiter().GetResult();
Juan Blanco
@juanfranblanco
Mar 23 2018 17:08
yes your transaction might take a while to be mined
you are probably better off sending the transaction only
and getting the hash and go to etherscan
and see how long it takes to be mined
also
it might be easier to use "await"
etc
Chandra Sekhar
@tcsekhar
Mar 23 2018 19:33
I'm calling it from a webservice and hence can't have a async on the method, and hence I had to go with GetAwaiter.GetResult.
I tried with not waiting and just calling the function. Even after 20 mins, I still don't see that transaction in the etherscan.io
Chandra Sekhar
@tcsekhar
Mar 23 2018 19:59

Here is the smart contract I'm trying to call (function: storeHash)
This is a test account and I don't care if its compromised - here is the creator private key "b3d7d06a45d2ae2b39f7296af2b03b02ad034b47e3660554ddb440f0610c37b7" for user account "0xf558e0532b817903b980bfd1164101aecb5c5368".

var account = new Nethereum.Web3.Accounts.Account("b3d7d06a45d2ae2b39f7296af2b03b02ad034b47e3660554ddb440f0610c37b7");
Nethereum.Contracts.Function function = new Nethereum.Web3.Web3(account, myContractObj.ethpooladdress)
                                            .Eth.GetContract(myContractObj.abi, myContractObj.contractaddress)
                                            .GetFunction("storeHash");
var transactionHash = function.SendTransactionAndWaitForReceiptAsync(myContractObj.senderaddress
                                                        , new HexBigInteger(9000000)
                                                        , new HexBigInteger(0)
                                                        , null 
                                                        , "Test"
                                                        , "Something"
                                                        , "1/1/2018");

When I don't wait for the hash, even after 20 mins, I still don't find the transaction in the ether.io