These are chat archives for Nethereum/Nethereum

18th
May 2018
Juan Blanco
@juanfranblanco
May 18 2018 05:56 UTC
what are you trying to do?
ramonB1996
@ramonB1996
May 18 2018 06:31 UTC
@juanfranblanco thx for the response. We fixed just after I asked yesterday, but thx anyways
Juan Blanco
@juanfranblanco
May 18 2018 06:32 UTC
you are happy I am happy ;)
Sergey Egorov
@egorov
May 18 2018 09:01 UTC
Hi, I'm trying to send tokens from smart contract using Nethereum library, but nothing happens. Ropsten returns something like TxHash, but I can't find it then at ropsten.etherscan.io. I think I have to use CreateTransactionInput to assembly transaction content. May be I wrong? Here is the code sample I used:
Contract contract =    web3.Eth.GetContract(abiString, contractAddress);
Function sendFunction = contract.GetFunction("send");
string data = sendFunction.CreateTransactionInput(contractAddress, new object[] { contractAddress, amount }).Data;
string trn = Web3.OfflineTransactionSigner.SignTransaction(contractPrivateKey, payeeAddress, 10, 200, 1000000000000L, 900000, data);
string result = await web3.Eth.Transactions.SendRawTransaction.SendRequestAsync("0x" + trn);
Juan Blanco
@juanfranblanco
May 18 2018 09:48 UTC
hi @egorov
check this workbook
Sergey Egorov
@egorov
May 18 2018 09:50 UTC
Thanx @juanfranblanco
Juan Blanco
@juanfranblanco
May 18 2018 09:50 UTC
you can run it using xamarin workbooks
but mainly you don't need to sign offline transactions
it is done for you now automatically in the background
you just need to
create your account
var web3 = new Web3(new Account(privateKey), url);
and that's it
Kirankumar
@kiranbasvaraj
May 18 2018 09:52 UTC

Hi all,
we have a smart contract which is emitting events after mapping is being updated and we are using filtered log referring to that event indexed by sender address but getting "0" as the response .
Here is my Code:

var func = contract.GetFunction("XyzFunction");
var transactionHash = await func.SendTransactionAsync(AppConstants.AdminWalletAddress, AppConstants.UserWalletAdress, xyz parameters);
var log= contract.GetEvent("xyzEvent");
var filterSender_snh = await log.CreateFilterAsync(AppConstants.UserWalletAdress);
var log = await Log_isSetNotaryHash.GetFilterChanges<XyzDtos>(filterSender_snh);

thanks,

Sergey Egorov
@egorov
May 18 2018 09:52 UTC
Thank you @juanfranblanco
Juan Blanco
@juanfranblanco
May 18 2018 09:52 UTC
if you use the code generator
in vscode that will create your project file
(files)
for all the messages
and you could do something like:
(that is another sample :) )
Sergey Egorov
@egorov
May 18 2018 09:54 UTC
Ok, I'll try it
Juan Blanco
@juanfranblanco
May 18 2018 09:57 UTC
@kiranbasvaraj you need to set the filter before you send the transaction
Kirankumar
@kiranbasvaraj
May 18 2018 10:02 UTC
@juanfranblanco now i am setting the filter before transaction but i am 0 again

var func = contract.GetFunction("XyzFunction");

var filterSender_snh = await log.CreateFilterAsync(AppConstants.UserWalletAdress);
var log= contract.GetEvent("xyzEvent");
var transactionHash = await func.SendTransactionAsync(AppConstants.AdminWalletAddress, AppConstants.UserWalletAdress, xyz parameters);
var log = await Log_isSetNotaryHash.GetFilterChanges<XyzDtos>(filterSender_snh);

Juan Blanco
@juanfranblanco
May 18 2018 10:09 UTC
how does your event look like?
solidity + csharp
Sergey Egorov
@egorov
May 18 2018 10:11 UTC
await sendFunction.EstimateGasAsync() throws an Nethereum.JsonRpc.Client.RpcResponseException: gas required exceeds allowance or always failing transaction
Web3 web3 = new Web3(new Account(contractPrivateKey), url);
Contract contract =
    web3.Eth.GetContract(contractABI, contractAddress);
Function send = contract.GetFunction("send");
HexBigInteger gas = await send.EstimateGasAsync(contractAddress, null, null, payeeAddress, 1000);
TransactionReceipt receipt = 
await send.SendTransactionAndWaitForReceiptAsync(contractAddress, gas, null, null, payeeAddress, 1000);
Juan Blanco
@juanfranblanco
May 18 2018 10:13 UTC
there might be an issue on your function
solidity
so it cannot estimate the gas
as it is failing
Sergey Egorov
@egorov
May 18 2018 10:16 UTC
 function send(address to, uint amount) public onlyOwner {
     require(to != address(0));
     require(amount > 0);

     balances[this] = balances[this].sub(amount);
     balances[to] = balances[to].add(amount);
     emit Transfer(this, to, amount);
}
Juan Blanco
@juanfranblanco
May 18 2018 10:17 UTC
is the privatekey corresponding to the owner?
Sergey Egorov
@egorov
May 18 2018 10:17 UTC
Yes
Juan Blanco
@juanfranblanco
May 18 2018 10:19 UTC
can you simplify it?
have you ran that in remix?
debug it?
or truffle?
Sergey Egorov
@egorov
May 18 2018 10:19 UTC
No
Juan Blanco
@juanfranblanco
May 18 2018 10:20 UTC
mainly since I cannot see what balances do
or balance
hence i mention to simplify it
you could remove the balances lines
Kirankumar
@kiranbasvaraj
May 18 2018 10:21 UTC
@juanfranblanco Event definition: event EventName (address indexed _senderAddress, bool Success);
Event called after update to mapping: emit EventName(msg.sender, true);
Juan Blanco
@juanfranblanco
May 18 2018 10:21 UTC
and see if the event is raised
sure
@kiranbasvaraj has the transasction succeded
is the Status 1 in the receipt?
can you see the logs of the receipt being populated?
Kirankumar
@kiranbasvaraj
May 18 2018 10:27 UTC
@juanfranblanco txn has succeded
Sergey Egorov
@egorov
May 18 2018 10:51 UTC
When I tried to set gas manually it throws an System.Exception: Invalid account used signing
Contract contract = web3.Eth.GetContract(contractABI, contractAddress);
Function send = contract.GetFunction("send");
TransactionReceipt receipt = 
    await send.SendTransactionAndWaitForReceiptAsync(contractAddress, new HexBigInteger(40433679), null, null, payeeAddress, 1);
Stef Heyenrath
@StefH
May 18 2018 10:51 UTC

@egorov Does require(to != address(0)); work correctly? I normally use just require(to!= 0);.

And I usually use await function.SendTransactionAsync(contractAddress, gas, null, payeeAddress, name) in combination with await _web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transaction).

Also what you can try is unit-testing this method, or deploy to test network.

Sergey Egorov
@egorov
May 18 2018 10:53 UTC
I'm trying to understand how to send tokens from contract with Nethereum
Ganesh Prasad Kumble
@0zAND1z
May 18 2018 11:07 UTC
You need to pass your wallet as the first arguement in the async call
Juan Blanco
@juanfranblanco
May 18 2018 11:08 UTC
SendTransactionAndWaitForReceiptAsync contractAddress
that is the problem
you need your accountAddress
as per @kggp1995 comment
i was blind I did not realised that you are passing the contractAddress instead of your address
this is the aim of the contract / query / transaction handlers
concentrate on the message
Juan Blanco
@juanfranblanco
May 18 2018 11:14 UTC
also when you have structs as an input / output / events
things are going to get more interesting with complex objects
Juan Blanco
@juanfranblanco
May 18 2018 11:19 UTC
codegenerationv1.gif
@egorov try this if you fancy
it is similar to the sample i sent before
we will be providing autogeneration also by nuget shortly
Juan Blanco
@juanfranblanco
May 18 2018 11:25 UTC
BTW the code generator does not support yet the unreleased solidity v2
but soon :)
Sergey Egorov
@egorov
May 18 2018 11:29 UTC
Thank you, I'll try it.
Juan Blanco
@juanfranblanco
May 18 2018 11:32 UTC
oh and check out remix / truffle when you need debugging
vs code here is not your friend yet :)
Sergey Egorov
@egorov
May 18 2018 11:35 UTC
Bingo! It's worked! Thank you all guys! You've saved my time!
Yes, vs code is not my friend, I'm frontend developer and my friend WebStorm usually
Juan Blanco
@juanfranblanco
May 18 2018 11:37 UTC
well it does the job for this ;)
but you are totally right that is why the codegen comes (will come) in many flavours
cli, autogen, ui, and library to hook in
(also in javascript)
dimonkov
@dimonkov
May 18 2018 12:03 UTC
@juanfranblanco ,
just wanted to ask, how to cancel SendTransactionAsync in web3?
Juan Blanco
@juanfranblanco
May 18 2018 12:04 UTC
well that will be send immediately
dimonkov
@dimonkov
May 18 2018 12:04 UTC
Yeah, sure.
But what if client has network problems, will it also return immediately?
Cause I don't want my app UI to stay in "Sending" state for a long time.
Just asking, haven't tested this yet.
Juan Blanco
@juanfranblanco
May 18 2018 12:11 UTC
no it will wait until it timesout
ill put something similar to what I have for IPC
dimonkov
@dimonkov
May 18 2018 12:13 UTC
Thanks.
I'll implement it differently for right now.
Juan Blanco
@juanfranblanco
May 18 2018 12:27 UTC
Nethereum/Nethereum@279f407
danielcostaext
@danielcostaext
May 18 2018 13:03 UTC

Quick help here, I have the following contract:
pragma solidity ^0.4.23;

contract NatCoin {
struct UserBalance {
uint natcoins;
string email;
string login;
}

mapping (uint => UserBalance) usersBalances;

function createUserNatCoins(uint id, string _login, uint _natcoin, string _email) public {
    usersBalances[id].login = _login;
    usersBalances[id].natcoins = _natcoin;
    usersBalances[id].email = _email;
}

function testContract() view public returns (string) {
    return "Hello";
}

function getUserBalance(uint id) view public returns (uint) {
    return usersBalances[id].natcoins;
}

}

I use nethereum to send a transaction:

var unlockAcc = await web3.Personal.UnlockAccount.SendRequestAsync(senderAddress, password, duration);
var contract = web3.Eth.GetContract(natcoinAbi, natcoinAddress);
var setUserNatCoins = contract.GetFunction("createUserNatCoins");
var transactionHash = await setUserNatCoins.SendTransactionAsync(senderAddress, new HexBigInteger(700000), new HexBigInteger(4000), 1 , "login1", 54, "login1@nas.com");
transactionHash = await setUserNatCoins.SendTransactionAsync(senderAddress, new HexBigInteger(700000), new HexBigInteger(4000), 2, "login2", 544, "login2@na.com");
var receipt = await MineAndGetReceiptAsync(web3, transactionHash);

And seems to work fine, but when I do a call to getUserBalance I always have a return of 0

What am I doing wrong here

Lee Haisen
@leehaisen01_gitlab
May 18 2018 13:07 UTC

i'm new to this so the question might not be appropreate.
but can we get the balance of an HD Wallet ? not balance of the accounts in it but the whole thing.

and i also want to know like can we have some kind of master addresses/private key in the HD wallet from where we can use the balance of all other addresses in the wallet, like collectively ?

Juan Blanco
@juanfranblanco
May 18 2018 13:14 UTC
@leehaisen01_gitlab check the hd wallet workbook in the docs or its repo
that will help to get started
Lee Haisen
@leehaisen01_gitlab
May 18 2018 13:21 UTC

@juanfranblanco i've checked it, coded it everything works fine just like it should. but the guy i'm making this thing for is asking me, that he want's to access all the accounts/addresses with the same private key and make transactions using that private key.

Yes! i did read about the mnemonics worldlist.

and the wallet.GetAddresses() gives me addresses just like it should but where is the Master Private key ?
or is there any private key like that or all the addresses in the HDwallet act like individual accounts ?

yes i also have seen the constructor of HdWallet with seedwords and password. and i guess that's not the master private key either.
Juan Blanco
@juanfranblanco
May 18 2018 13:28 UTC
all the addresses act as individual accounts
but they get created using the same seed
hak
@hakart_twitter
May 18 2018 13:30 UTC
Guys is https://api.myetherapi.com/eth link valid link to sent transactions for Ethereum blockchain I just use only Ropsten test ropsten.infura.io. What is the real Ethereum blockchain link ?
Lee Haisen
@leehaisen01_gitlab
May 18 2018 13:30 UTC
@juanfranblanco Thanks alot.
Lee Haisen
@leehaisen01_gitlab
May 18 2018 13:38 UTC
@juanfranblanco one last thing. Can i get the collective balance of a single wallet ?
check that
i have started a repo for questions :)
@leehaisen01_gitlab you will have to iterate per each account address
and add it all up
i guess you knew that
so there is not a function for query many balances at once
could be added to the Hdwallet i guess
Lee Haisen
@leehaisen01_gitlab
May 18 2018 14:17 UTC
@juanfranblanco Thanks again.
that describes it
you only have 2
main (eth) and the other is (Ropsten)
have not used it before, but i guess it will be ok
danielcostaext
@danielcostaext
May 18 2018 14:59 UTC
@juanfranblanco thanks very much!!
Juan Blanco
@juanfranblanco
May 18 2018 15:15 UTC
not bother, i thought it will be easier :)