These are chat archives for Nethereum/Nethereum

1st
May 2018
sudeep-nigam
@sudeep-nigam
May 01 2018 09:24

Dear community
I am new to block chain and nethereum. Please help me out I am getting following error on first line of code.
Regards
Error occurred when trying to send rpc requests(s)
Nethereum.JsonRpc.RpcClient

Here is the code

var isAccountUnlocked = await web3.Personal.UnlockAccount.SendRequestAsync(senderWallet, senderWalletPassword, 10000);

            if (isAccountUnlocked)
            {
                //When sending the transaction using the transaction manager for a managed account, personal_sendTransaction is used.
                //var transactionReceipt = await transactionPolling.SendRequestAsync(() =>
                //web3.TransactionManager.SendTransactionAsync(senderWallet, recipientWallet, new HexBigInteger(amount)));

                var transactionReceipt = await transactionPolling.SendRequestAndWaitForReceiptAsync(() =>
                web3.TransactionManager.SendTransactionAsync(senderWallet, recipientWallet, new HexBigInteger(amount)));
                var test1 = transactionReceipt.Status;
JEN
@chukwuemekanweke
May 01 2018 16:00

@isgroupsrl_twitter it depends on your use case.

if you have an only owner modifier on the transfer function then all you need to do is ensure that whatever code that would be calling that transfer function does not have a value greater than the maximum allowed value for uint256

But if the function is going to be accessible to everyone as is common with the ERC20 Standard, batch processing is not a wise thing to do. It's going to make your contract unstable and hackable

Psilon
@Pzixel
May 01 2018 16:31
Hello there
I have a question: how can I get all occured events?
I mean can I query some events that occured somewhere in the past? I see Parity UI can do it
@juanfranblanco I also encountered a problem with enums today: I have manually cast them in order to make them work
Need small IntEncoder enhancement. I'l do it myself if I get some time, but FYI there is this problem
Juan Blanco
@juanfranblanco
May 01 2018 16:58
Enums are ints?
So yes there is no type conversion at the moment
Psilon
@Pzixel
May 01 2018 17:04
Well, my enums are uint8 (because it's what ABI shows so I always declare C# types corresponding to ABI types)
however, I see that you have much bigger problems such as tuples/structurs results
It's a pain that I cannot return (uint64, uint64, string) and I have to declare 3 separate methods in contract
in order to be able to call it from C#
Pari Hoxha
@phoxha
May 01 2018 17:53
@sudeep-nigam did you get this solved yet. I am having the same issue and all I am trying to do is:
var transaction = await web3.TransactionManager.SendTransactionAsync(account.Address, account2.Address, new Nethereum.Hex.HexTypes.HexBigInteger(wei));
I am getting: Message: Nethereum.JsonRpc.Client.RpcClientUnknownException : Error occurred when trying to send rpc requests(s)
---- System.Net.Http.HttpRequestException : Response status code does not indicate success: 405 (Method Not Allowed).
using var web3 = new Web3("https://rinkeby.infura.io/aIbB......
I get my account balance ok just cant send anything
By the way @juanfranblanco , its amazing what you have done. Great work. Just trying to figure things out.
Steven
@code-sergeant
May 01 2018 18:13
Hello everyone! I'm new to Nethereum, and had a question about using Nethereum to unlock the Ganache local account I'm using to deploy a test contract. Here is my code below:
 // Here we are specifying which provider/node we will be interacting with to talk to the blockchain.
            var provider = "http://127.0.0.1:7545";
            var web3 = new Web3(provider);

            // The ABI is similar to an API. It gives us instructions for interacting with the contract once it is deployed. 
            var abi = File.ReadAllText(path: @"C:\Sabio\Blockchain\Nethereum\NethereumConsoleAppSample\NethereumConsoleAppSample\abi.json");
            // Bytecode is what a Solidity contract compiles down to and is what the Ethereum Virtual Machine uses to execute the commands specified in the contract interface. 
            var byteCode = "608060405234801561001057600080fd5b506101a5806100206000396000f300608060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680635390052214610046575b600080fd5b34801561005257600080fd5b506100cd600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091929192905050506100cf565b005b806040518082805190602001908083835b60208310151561010557805182526020820191506020810190506020830392506100e0565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405180910390208273ffffffffffffffffffffffffffffffffffffffff167f34867b5ac3ee5ed28d673e1c5d2ee02b96a780d177ba94f03b0988d69ef9fdd460405160405180910390a350505600a165627a7a72305820d49b6a7afd665ec3a3ca8cf7805ceec9a1f94c4f5eba3b3a61d4d53dc94312610029";

            var wordList = "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat";
            var password = "password";
            var wallet = new Wallet(words: wordList, seedPassword: password);
            var senderAddress = wallet.GetAccount(index: 0).Address;

            // Here we are unlocking the address we will be using to send gas/funds for the next 2 minutes while we are deploying this contract programmatically. 
            var unlockResult = await web3.Personal.UnlockAccount.SendRequestAsync(address: senderAddress, passPhrase: password, durationInSeconds: 120);

            Console.WriteLine("We will now deploy a contract to our node using the following data:");
            Console.WriteLine("Abi: {0}", abi);
            Console.WriteLine("Bytecode: {0}", byteCode);
            Console.WriteLine();
            Console.WriteLine("From address[0]: {0}", senderAddress);
            Console.WriteLine("Press any key to deploying this contract...");
            Console.ReadLine();

            // When we deploy a contract, we get back a transaction hash that we can use later on to get the deployed contract's public key address. 
            var transactionHash = await web3.Eth.DeployContract.SendRequestAsync(abi: abi, contractByteCode: byteCode, from: senderAddress, gas: new HexBigInteger(900000));
            var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash: transactionHash);
            var contractAddress = receipt.ContractAddress;
But when I run the console app, I keep getting this error when it gets to the unlockResult call
Nethereum.JsonRpc.Client.RpcResponseException: 'Account not found'
Enigmatic
@EnigmaticUnreal_twitter
May 01 2018 18:19

@phoxha @sudeep-nigam

If you're connecting to a public node like infura, use something like:

account = Accounts.Account.LoadFromKeyStore("C:\keystorefile", password)
iweb3 = New Web3(account, "https://rinkeby.infura.io/")

This loads a JSON keystore file, initialises the account object with the password.

If you're using a private key straight up, the below will do:

Dim delegatedAccount = New Nethereum.Web3.Accounts.Account(privateKey)
iweb3 = New Web3(delegatedAccount, "https://rinkeby.infura.io/")

https://nethereum.readthedocs.io/en/latest/accounts/

@code-sergeant

Did the address load up fine (double checking if the mnemonics generated the same addresses)? Off the top of my head Ganache accounts should already be unlocked, so you should be able to fire transactions without calling unlock separately.

Steven
@code-sergeant
May 01 2018 18:23
@EnigmaticUnreal_twitter The address loads up fine, and I tried it without unlocking before which threw an error.
I also tried it without a password, which threw an error saying that parameter could not be null
When I don't try to unlock it and go straight to the transactionHash line to deploy the contract, the error I get is:
System.Exception: 'Unable to convert the result to type Nethereum.RPC.Eth.DTOs.TransactionReceipt'
Enigmatic
@EnigmaticUnreal_twitter
May 01 2018 18:55

Sorry - Had to deal with something for a bit.

You should be able to use the address outright, no unlocking needed. Just pass Nothing as your password.

Let me cook up a quick example in C#. The current one I have is in VB.

Enigmatic
@EnigmaticUnreal_twitter
May 01 2018 19:00
My example in VB. Trying to get my C# project to work in the meantime (blushes)
Dim wordList = "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat"
Dim wallet = New Wallet(wordList, Nothing)
Dim account = wallet.GetAccount(0)

'insert compiled contracts and initialise web3
Dim tAbi = ""
Dim tCode = ""
Dim tweb3 = New Web3("http://localhost:8545/")

Dim tgas = New HexBigInteger(2500000)
Dim testing = Await tweb3.Eth.DeployContract.SendRequestAsync(tAbi, tCode, account.Address, tgas)
Dim treceiptHash = Await tweb3.Eth.DeployContract.SendRequestAndWaitForReceiptAsync(tAbi, tCode, account.Address, tgas)
Pari Hoxha
@phoxha
May 01 2018 19:09
@EnigmaticUnreal_twitter Thank you! Thank you!
Enigmatic
@EnigmaticUnreal_twitter
May 01 2018 19:15

@code-sergeant

C#

var wordList = "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat";
var wallet = new Wallet(wordList, null);
var senderAddress = wallet.GetAccount(0).Address;

var abi = @"";
var byteCode = "";
var web3 = new Web3.Web3("http://localhost:8545/");
var gas = new HexBigInteger(3000000);

var transactionHash = await web3.Eth.DeployContract.SendRequestAsync(abi, byteCode, senderAddress, gas);
var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);
@phoxha you're welcome
Juan Blanco
@juanfranblanco
May 01 2018 19:33
@Pzixel what? are you saying that you have to declare 3 methods to return multiple outputs?
no you don't need to, just decode to an object
use the code generator to see how it is done
structs is not a feature yet of the current solidity
that is coming in v2
struct output, fut it works the same (and it will work the same as the Deserialising to Object)
Psilon
@Pzixel
May 01 2018 19:36
@juanfranblanco i googled that nethereum doesn't support tuples
Juan Blanco
@juanfranblanco
May 01 2018 19:37
you can output multiple outputs
try it
tuples is v2 with which is what structs are converted to
Juan Blanco
@juanfranblanco
May 01 2018 19:44
image.png
image.png
Psilon
@Pzixel
May 01 2018 19:57
But it's a tuple, isn't it?
Ah i see
if you name them and init
then it works differently?
Juan Blanco
@juanfranblanco
May 01 2018 19:57
well the init
is just to demo
you can doe whatever you want
they can be anonymous parameters
but Nethereum will code generate some names for you for the DTO
the issue with tuples is that the abi has something call tuple in v2
so that is something completely different
but yeah v2 brings lots of features, but until ready is better not to trial and error
there is a nuget now for the integration tester
for usage
check
Psilon
@Pzixel
May 01 2018 20:11
I mean
function foo() returns (uint a, uint b) { a = 1; b = 2 }
works fine
and function foo() returns (uint, uint) { return (1,2) } doesn't?
JEN
@chukwuemekanweke
May 01 2018 20:46
@Pzixel You can do this with NEthereum. But generally you'd want to use etherscan's API for this
Psilon
@Pzixel
May 01 2018 20:47
@chukwuemekanweke I already changed my implementation on internal list
now I want to return several values in one request
so I asked a question you can see just a little bit above
JEN
@chukwuemekanweke
May 01 2018 21:07
function foo() returns (uint a, uint b) { 
a=1;
b=2;
return(a,b);
 }
Psilon
@Pzixel
May 01 2018 21:14
so I can return them
great
but I should name them in order to make them work or I could just pass it in same order?
well
it look much better anyway
Psilon
@Pzixel
May 01 2018 22:50
Okay, what's wrong then?
    function getStatusUpdate(uint index) public view returns(uint64, uint64, string) {
        StatusUpdate storage update = statusUpdates[index];
        return (update.updateDate, update.statusCode, update.note);
    }
    [FunctionOutput]
    public class StatusUpdateStruct
    {
        [Parameter("uint64", 1)]
        public long UpdateDate { get; set; }
        [Parameter("uint64", 2)]
        public long StatusCode { get; set; }
        [Parameter("string", 3)]
        public string Note { get; set; }
    }
            var statusUpdatesCount = await Contract.GetFunction("getStatusUpdatesCount").CallAsync<int>();
            var getStatusUpdate = Contract.GetFunction("getStatusUpdate");
            var tasks = Enumerable.Range(0, statusUpdatesCount).Select(async i =>
            {
                var statusUpdate = await getStatusUpdate.CallAsync<StatusUpdateStruct>(i);
                ...
            });
            ...
System.NotSupportedException : Core.Contract.StatusUpdateStruct is not a supported decoding type for IntType
   at Nethereum.ABI.Decoders.IntTypeDecoder.Decode(Byte[] encoded, Type type)
   at Nethereum.ABI.ABIType.Decode(Byte[] encoded, Type type)
   at Nethereum.ABI.FunctionEncoding.ParameterDecoder.DecodeOutput(String output, ParameterOutput[] outputParameters)
   at Nethereum.ABI.FunctionEncoding.FunctionCallDecoder.DecodeSimpleTypeOutput[T](Parameter outputParameter, String output)
   at Nethereum.Contracts.FunctionBuilderBase.DecodeSimpleTypeOutput[TReturn](String output)
   at Nethereum.Contracts.FunctionBase.<CallAsync>d__17`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---