These are chat archives for Nethereum/Nethereum

4th
Dec 2018
keepbreath
@keepbreath
Dec 04 2018 07:21
Hello,It's been a long time,I have some questions to ask, how can I save Gas by Nethereum bulk sending transactions?
Enigmatic
@EnigmaticUnreal_twitter
Dec 04 2018 09:15

Hello,It's been a long time,I have some questions to ask, how can I save Gas by Nethereum bulk sending transactions?

Hey how are you? :D

For ERC20s I guess? For ERC20s you'll have the flexibility to create a bulk transfer function to help with multiple transfers, which could accept an array of addresses and an array of value (tokens to send).

(just be a bit mindful of the batchTransfer implementation bug reported a few months back: https://medium.com/@peckshield/alert-new-batchoverflow-bug-in-multiple-erc20-smart-contracts-cve-2018-10299-511067db6536)

MANOJKUMARCH
@MANOJKUMARCH
Dec 04 2018 14:11

@juanfranblanco , I tried to follow the link you gave, but couldn't get any positive result. I am trying to return 2 arrays of address, but I am getting null values in Nethereum. Below is the code snippet

var getSignatoriesAndConMem = contract.GetFunction("getSignatoriesAndConMem");
var gasGet = getSignatoriesAndConMem.EstimateGasAsync(account.Address, new HexBigInteger(900000), new HexBigInteger(0));
var data = await getSignatoriesAndConMem.SendTransactionAsync(account.Address, gasGet.Result, new HexBigInteger(10), null, null);
var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(data);
var mem = await getSignatoriesAndConMem.CallDeserializingToObjectAsync<Mem>().ConfigureAwait(false);
//return result;
return mem;

public class Mem
{
//public long Index { get; set; }

    [Parameter("address payable[]", 1)]
    public string[] _signatories { get; set; }

    [Parameter("address[]", 2)]
    public string[] _contractMembers { get; set; }
}

I tested my solidity code in remix ide and it worked fine. But I am unable to get the details in Nethereum, please check and help

Enigmatic
@EnigmaticUnreal_twitter
Dec 04 2018 15:25

Hmmm. I think it's how the parameters are set (e.g. if it is returning two separate arrays, both of them should be address[].

That said, have you tried using the code generator @MANOJKUMARCH ?

For example
image.png
image.png
image.png
So all the class DTOs and service wrappers are generated for you. :D
(don't mind my example in VB though)
Juan Blanco
@juanfranblanco
Dec 04 2018 15:27
VB.NET is awesome!
(and the example!)
nice to see it used, really :)
Matthew Morrison
@matthewsmorrison
Dec 04 2018 15:29
Hi all - I am new to the channel (and Nethereum) but have extensive experience using Ethereum. I was just wondering whether anyone has used Nethereum + Quorum + Kaleido (https://kaleido.io/) in their tech stack? I am having problems retrieving state of a smart contract deployed using the 'privateFor' field. Thanks a lot!
MANOJKUMARCH
@MANOJKUMARCH
Dec 04 2018 15:30
@EnigmaticUnreal_twitter , thanks for the example given, and I did not get what is regarding code generator? Is it specific to VB. I am using C# and I have done the compilation and got the required abi and byte code
Regarding the DTOs, I am not clear on it. I am new to C# and still struggling with things. So could you help me on what is it
Enigmatic
@EnigmaticUnreal_twitter
Dec 04 2018 15:31

@juanfranblanco :D :D It does help me figure out how should I build my DTOs, saving me tons of time really.

@MANOJKUMARCH - The code generator is a plugin which is available through Visual Studio Code, and yes it's available for C#. I think I am the minority here actually.

Juan Blanco
@juanfranblanco
Dec 04 2018 15:33
Hi @matthewsmorrison I have not tested that combination, do you get any errors?
Enigmatic
@EnigmaticUnreal_twitter
Dec 04 2018 15:33
image.png
MANOJKUMARCH
@MANOJKUMARCH
Dec 04 2018 15:35
@EnigmaticUnreal_twitter when I use code generate for my solidity code i get this
\Error generating code:
Unexpected token p in JSON at position 0
Juan Blanco
@juanfranblanco
Dec 04 2018 15:35
@MANOJKUMARCH which file are you using to code generate
Enigmatic
@EnigmaticUnreal_twitter
Dec 04 2018 15:36
@MANOJKUMARCH - Might be because you're on your .sol file? Might want to jump over to your JSON output.
image.png
MANOJKUMARCH
@MANOJKUMARCH
Dec 04 2018 15:36
@EnigmaticUnreal_twitter , okay, you mean I need to use my ABI?
@EnigmaticUnreal_twitter got it now
Enigmatic
@EnigmaticUnreal_twitter
Dec 04 2018 15:37
Hope it works - Let us know how the output is like compared to the class above, am curious. :D
Matthew Morrison
@matthewsmorrison
Dec 04 2018 15:39

@juanfranblanco Thanks for the quick response (and I didn't realise that Nethereum is also part of Consensys as well as Kaleido)! Everything is working very smoothly:

1) Deploy a smart contract from Node A using privateFor = ['PRIVATE_TX_ADDRESS_NODEB']
2) Create a web3 instance using Node B
3) At this point Node B actually can't retrieve any state from that smart contract and, furthermore, it seems to not exist given the return from this is '0x' String code = await web3.Eth.GetCode.SendRequestAsync(CONTRACT_ADDRESS);

@juanfranblanco I may be making a mistake though. In a Quorum private contract call do you need to specify an address? I am assuming no.
Juan Blanco
@juanfranblanco
Dec 04 2018 15:42
yes, everything works the same, the only thing that changes is that an extra field is included "privateFor"
have you got a snippet of the code you are using?
well really is just this
 var privateFor = new List<string>(new[] { "ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc=" });

            web3Node1.SetPrivateRequestParameters(privateFor);
Matthew Morrison
@matthewsmorrison
Dec 04 2018 15:47
In terms of the original contract deployment
List<String> privateFor = new List<String>();
privateFor.Add(NODEB_PRIVATE_TX_ADDR);
var web3 = BlockchainConnection.EstablishPrivateBlockchainConnection(NODEA_RPC_ENDPOINT);
var newAccount = web3.Personal.NewAccount.SendRequestAsync("password");
var unlockAccountResult = await web3.Personal.UnlockAccount.SendRequestAsync(newAccount.Result.ToString(), "password", 120);

 web3.SetPrivateRequestParameters(privateFor);
 string abi = Utils.GetFileContents(@"Contracts\Project.abi");
 string byteCode = "0x" + Utils.GetFileContents(@"Contracts\Project.bin");
 web3.TransactionManager.DefaultGasPrice = 0;
 var transactionHash = await web3.Eth.DeployContract.SendRequestAsync(abi, byteCode, newAccount.Result, new HexBigInteger(50000000), MORTA_CONTRACT, name);
 var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);
Juan Blanco
@juanfranblanco
Dec 04 2018 15:50
did your contract deploy succesfully?
Matthew Morrison
@matthewsmorrison
Dec 04 2018 15:51
In terms of the contract call:
List<String> privateFor = new List<String>(new[] { NODEA_PRIVATE_TX_ADDR });
 var web3 = BlockchainConnection.EstablishPrivateBlockchainConnection(NODEB_RPC_ENDPOINT);
 string abi = Utils.GetFileContents(@"Contracts\Project.abi");
 var contract = web3.Eth.GetContract(abi, PRIVATE_PROJECT);
 web3.SetPrivateRequestParameters(privateFor);

 String code = await web3.Eth.GetCode.SendRequestAsync(CONTRACT_ADDR);

 var getActiveFunction = contract.GetFunction("isActive");
 Boolean result1 = await getActiveFunction.CallAsync<Boolean>();

 System.Diagnostics.Debug.Write(Environment.NewLine);
 System.Diagnostics.Debug.Write("The contract is active: " + result1);
 System.Diagnostics.Debug.Write(Environment.NewLine);

 var getModelFunction = contract.GetFunction("getLatestVersion");
 String result = await getModelFunction.CallAsync<String>();
 return result;
Yes the contract deployed successfully as shown by the Kaleido block explorer
Juan Blanco
@juanfranblanco
Dec 04 2018 15:53
ok interesting
Matthew Morrison
@matthewsmorrison
Dec 04 2018 15:53

I have a feeling the problem could stem from:

1) Needing to use an account on Node B to make contract calls (although I wouldn't think this is necessary)
2) Incorrect setting of the privateFor parameters when trying to retrieve a state

or 3) Something I have missed :)
Juan Blanco
@juanfranblanco
Dec 04 2018 15:54
so mainly it is working, because your deployment is succesful
Matthew Morrison
@matthewsmorrison
Dec 04 2018 15:54
Yes absolutely
Juan Blanco
@juanfranblanco
Dec 04 2018 15:54
you never know with all the combinations :)
Matthew Morrison
@matthewsmorrison
Dec 04 2018 15:54
Just retrieval of the state from Node B is not
haha true
Juan Blanco
@juanfranblanco
Dec 04 2018 15:55
getCode will not get you anything because is private
Matthew Morrison
@matthewsmorrison
Dec 04 2018 15:56
Yes that makes sense
Juan Blanco
@juanfranblanco
Dec 04 2018 15:58
and similar to state
MANOJKUMARCH
@MANOJKUMARCH
Dec 04 2018 15:58
@EnigmaticUnreal_twitter , I have tried to generate the code, but the DTOs which you showed in VB are not created
Juan Blanco
@juanfranblanco
Dec 04 2018 15:58
you need to be connected to the node private node
so that migth be the issue
Matthew Morrison
@matthewsmorrison
Dec 04 2018 15:59
Yes that is what I do with the function EstablishPrivateBlockchainConnection:
 public static Web3Quorum EstablishPrivateBlockchainConnection(String rpcEndpoint) {
        var byteArray = Encoding.ASCII.GetBytes(USER + ":" + PASS);
        AuthenticationHeaderValue auth = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
        IClient client = new RpcClient(new Uri(rpcEndpoint), auth, null, null, null);
        var web3 = new Web3Quorum(client);
        return web3;
    }
I then get a Web3Quorum instance which is the web3 object I use above
This is where I use Node B's RPC Endpoint
Juan Blanco
@juanfranblanco
Dec 04 2018 16:00
ok got you so apart from adding the kaleido headers you are also connecting to the right node to get the private state
Enigmatic
@EnigmaticUnreal_twitter
Dec 04 2018 16:00
@MANOJKUMARCH - Hmmmmm. Is there a ContractDefinition folder?
image.png
Matthew Morrison
@matthewsmorrison
Dec 04 2018 16:01
Yes correct. I am connecting to Node B which is the private TX address I used when deploying the contract
MANOJKUMARCH
@MANOJKUMARCH
Dec 04 2018 16:02
image.png
@EnigmaticUnreal_twitter , Yes, but DTOs are not available in it
Juan Blanco
@juanfranblanco
Dec 04 2018 16:03
@matthewsmorrison hmm then yes you should get the data, if Kaleido is not doing something different
and yeah you should be able to see the code from that node
Enigmatic
@EnigmaticUnreal_twitter
Dec 04 2018 16:04
@MANOJKUMARCH - Interesting, how does the solidity function looks like? Could you share the code and I'll give it a quick test myself?
Juan Blanco
@juanfranblanco
Dec 04 2018 16:04
it all indicates you are not connected to that node
MANOJKUMARCH
@MANOJKUMARCH
Dec 04 2018 16:05
@EnigmaticUnreal_twitter Below is the code
function setSignatoriesAndConMem(address payable[] memory _signatories, address[] memory _contractMembers) public onlyOwner payable returns(bool, uint, uint, uint){
signatories = _signatories;
contractMembers = _contractMembers;
emit initialMembersAdded(_signatories, _contractMembers);
return (true, signatories.length, bytes(filehash).length, address(this).balance);
}
function getSignatoriesAndConMem()public onlyAuthorised returns(address payable[] memory _signatories, address[] memory _contractMembers){
    _signatories = signatories;
    _contractMembers = contractMembers;
    return(_signatories, _contractMembers);
}
Matthew Morrison
@matthewsmorrison
Dec 04 2018 16:10

@juanfranblanco One thing I can do to check is list all the accounts on that node.

I could use var accounts = web3.Personal.ListAccounts;. What does this return / how would I print all the accounts that it has found?

Juan Blanco
@juanfranblanco
Dec 04 2018 16:10
well those will be the accounts on that particular node
Matthew Morrison
@matthewsmorrison
Dec 04 2018 16:11
So when I run that I get all the accounts listed on that node within Kaleido. This implies my web3 object is connected to the right node.
Juan Blanco
@juanfranblanco
Dec 04 2018 16:11
so yeah that will be a good check, you can validate if one of the accounts matches the one of the node, or the one you did the deployment
yeah
read my mind
Matthew Morrison
@matthewsmorrison
Dec 04 2018 16:12
:)
I wish that was the error though....
Juan Blanco
@juanfranblanco
Dec 04 2018 16:13
well it is designed (Quorum) like that, well even Ethereum. Mainly it returns null on state when there is nothing there
Matthew Morrison
@matthewsmorrison
Dec 04 2018 16:14
In my contract I set isActive to true in the constructor. Therefore this node should read 'True' when getting that value but instead it is reading False.
Juan Blanco
@juanfranblanco
Dec 04 2018 16:15
yes it is returning 0
or null
0 == false
Matthew Morrison
@matthewsmorrison
Dec 04 2018 16:15
Yes
so for some reason that contract is not visible to that node
Juan Blanco
@juanfranblanco
Dec 04 2018 16:15
correct
Matthew Morrison
@matthewsmorrison
Dec 04 2018 16:17
This could be a Kaleido specific issue with Constellation / the Quorum specific transaction manager not working correctly?
Juan Blanco
@juanfranblanco
Dec 04 2018 16:17
well you can see the contract being deployed
on that node?
using the explorer correct? so the Constellation should be fine, only thing I can think is the connection to the node
i pinged them, lets see if i get any response
Yes the contract being deployed is shown in the explorer with the little lock icon indicating its a private transaction.
Juan Blanco
@juanfranblanco
Dec 04 2018 16:24
got no access to the file
but that is great I will post that too to them
Should work now - apologies
Juan Blanco
@juanfranblanco
Dec 04 2018 16:25
ha ha don't worry
Matthew Morrison
@matthewsmorrison
Dec 04 2018 16:26
Thanks for all your help by the way - hopefully this will help all the following people who want to set up something similar :)
Juan Blanco
@juanfranblanco
Dec 04 2018 16:26
yeah, lets see what is the answer :)
Enigmatic
@EnigmaticUnreal_twitter
Dec 04 2018 16:27
@MANOJKUMARCH - Ahhh. Can't believe I didn't notice this right off the bat. >_<
image.png

For function getSignatoriesAndConMem() you might want to specify "view", so you could get the return values.

That's probably why the generator did not give you anything. :)

Juan Blanco
@juanfranblanco
Dec 04 2018 16:29
@matthewsmorrison only thing I can also see being an issue is that it is showing a correct contract deployment, but it has not deployed succesfuly
but there is no indication of it in the explorer
Matthew Morrison
@matthewsmorrison
Dec 04 2018 16:35
Yes that could be true. Given that the block explorer node does not have access to the contract bytecode / status they could just be reporting successful deployment regardless of what happens.
MANOJKUMARCH
@MANOJKUMARCH
Dec 04 2018 16:37
@EnigmaticUnreal_twitter Yeah, I see now the DTO is created, but if you have observed the DTO is not created for setSignatoriesAndConMem and this function also returns values. We cannot have "view" to this function as it changes the state. :(
Enigmatic
@EnigmaticUnreal_twitter
Dec 04 2018 16:39
Ah yes that's the case for solidity functions. A state changing function can't return values, but I noticed that you have emitted an event so you could use that to ensure your function has ran.
    [Event("initialMembersAdded")]
    public class InitialMembersAddedEventDTOBase : IEventDTO
    {
        [Parameter("address[]", "", 1, false )]
        public virtual List<string> ReturnValue1 { get; set; }
        [Parameter("address[]", "", 2, false )]
        public virtual List<string> ReturnValue2 { get; set; }
    }
(mine might be a bit different as I was tinkering with the event just now :))
Enigmatic
@EnigmaticUnreal_twitter
Dec 04 2018 16:42
Oh wow Winforms going open source :D :D
Juan Blanco
@juanfranblanco
Dec 04 2018 16:42
yes and wpf
netcore 3.0
is going to be huge
Enigmatic
@EnigmaticUnreal_twitter
Dec 04 2018 16:43
Winforms in Linux. wipes a tear
that will be eto.forms which is awesome
Enigmatic
@EnigmaticUnreal_twitter
Dec 04 2018 16:54
jaws dropped at the demo @ connectevent oh wow....
system.xaml
Roy
@Shammah
Dec 04 2018 22:08
Does the project have some kind of roadmap, to-do or up-for-grabs list? I'd love to contribute, but I'm not sure where to start and where (some easy) work is to be done. Can't find it in the website, readme, issue tracker or other doc.
Juan Blanco
@juanfranblanco
Dec 04 2018 22:42
hi Roy, i will put a road map in the near future :)
but mostly more blockchain components, better integrations, full functional applications, more backend, etc, etc
more tooling :)
templates, code generators for frontend, backend
Roy
@Shammah
Dec 04 2018 22:52
So in short; better everything ;)
I'll see what I can manage
Juan Blanco
@juanfranblanco
Dec 04 2018 23:13
yeah :)
the idea is that any developer should be able to get started very quickly with mobile, desktop, web (blazor)
i started created a simple common patterns to allow for code generation of uis, but yes that is just the start..