These are chat archives for Nethereum/Nethereum

14th
Dec 2018
Juan Blanco
@juanfranblanco
Dec 14 2018 09:25 UTC
@rsantirso if you are batching transactions, you need to have a single instance of Web3, we manage internally nonce(s). The nonces is what it makes each transaction unique
The accounts calling the transaction are shared between them and, in fact, sometimes I get an rpc exception about 'already known transaction' (that's the message, more or less).
So if you are using different programs, processes the best thing is to use different accounts per process, or have a nonce provider microservice for the accounts
Lyon.Nee
@LyonNee
Dec 14 2018 09:33 UTC
Hello ! want to get the argument that I entered when I called the contract method.I tried this method but failed
var functionInput = transaction.DecodeTransactionToFunctionMessage<PublishFunction>();
Juan Blanco
@juanfranblanco
Dec 14 2018 09:34 UTC
what is the error?
Lyon.Nee
@LyonNee
Dec 14 2018 09:36 UTC
System.ArgumentException: The transaction given is not for the current function
Parameter name: transaction
   at Nethereum.Contracts.MessageEncodingServices.FunctionMessageEncodingService`1.DecodeTransactionInput(TContractFunction contractMessageOuput, Transaction transaction)
   at EthTransToExcl.Do.ShouldBeAbleCallAndReadEventLogs(List`1 results) in E:\Git_Work\EthTransToExcl\EthTransToExcl\Do.cs:line 33
This is the code for the smart contract

  function setAllocation(address _address, uint256 total_value, uint[] times, uint256[] balanceRequires) public onlyOwner returns (bool)
Juan Blanco
@juanfranblanco
Dec 14 2018 09:38 UTC
well that is not the PublishFunction
it is the setAllocation
maybe is a typo?
Lyon.Nee
@LyonNee
Dec 14 2018 09:39 UTC

    [Function("publish")]
    public class PublishFunctionBase : FunctionMessage
    {
        [Parameter("address", "retailer", 1)]
        public virtual string Retailer { get; set; }
        [Parameter("string", "stdPromoJson", 2)]
        public virtual string StdPromoJson { get; set; }
    }

    [Function("transfer")]
    public class TransferFunction : PublishFunctionBase
    {

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

        [Parameter("uint256", "_value", 2)]
        public BigInteger Value { get; set; }
    }

    [Function("setAllocation")]
    public class SetAllocationFunction : PublishFunctionBase
    {
        [Parameter("address", "_address", 1)]
        public string Address { get; set; }

        [Parameter("uint256", "total_value", 2)]
        public BigInteger Value { get; set; }

        [Parameter("uint[]", "times", 3)]
        public BigInteger Times { get; set; }

        [Parameter("uint256[]", "balanceRequires", 4)]
        public BigInteger BalanceRequires { get; set; }
    }
Juan Blanco
@juanfranblanco
Dec 14 2018 09:40 UTC
sure but what transaction is it for?
Lyon.Nee
@LyonNee
Dec 14 2018 09:40 UTC
   var account = new Account(privateKey);
                var web3 = new Web3(account, url);
                foreach (var result in results)
                {
                    var transactionHash = result.hash;
                    var transaction = await web3.Eth.Transactions.GetTransactionByHash.SendRequestAsync(transactionHash);
                    var functionInput = transaction.DecodeTransactionToFunctionMessage<SetAllocationFunction>();
                }
erc20 token transfer
Juan Blanco
@juanfranblanco
Dec 14 2018 09:41 UTC
setAllocation, or Publish
also SetAllocationFunction should not inherit from PublishFunctionBase
Lyon.Nee
@LyonNee
Dec 14 2018 09:43 UTC
What should I write?
Juan Blanco
@juanfranblanco
Dec 14 2018 09:43 UTC
FunctionMessage?
there are all different types aren't they?
SetAllocationFunction : FunctionMessage
and your decoding should be for the transaction
what has happened is that the transaction did not match the function itself
this is know as we decode the signature
which includes all parameters and functionname
Lyon.Nee
@LyonNee
Dec 14 2018 09:47 UTC
I don not understand
sorry
Juan Blanco
@juanfranblanco
Dec 14 2018 09:48 UTC
ok
Lyon.Nee
@LyonNee
Dec 14 2018 09:48 UTC
I'm a new programmer
Juan Blanco
@juanfranblanco
Dec 14 2018 09:48 UTC
SetAllocationFunction needs to inherit from FunctionMessage
Lyon.Nee
@LyonNee
Dec 14 2018 09:48 UTC

    [Function("setAllocation")]
    public class SetAllocationFunction : FunctionMessage
    {
        [Parameter("address", "_address", 1)]
        public string Address { get; set; }

        [Parameter("uint256", "total_value", 2)]
        public BigInteger Value { get; set; }

        [Parameter("uint[]", "times", 3)]
        public BigInteger Times { get; set; }

        [Parameter("uint256[]", "balanceRequires", 4)]
        public BigInteger BalanceRequires { get; set; }
    }
Juan Blanco
@juanfranblanco
Dec 14 2018 09:48 UTC
TransferFunction needs to inherit from FunctionMessage too
yeah
as they are different types all together and not using the same function
Lyon.Nee
@LyonNee
Dec 14 2018 09:49 UTC
Is there anything else that needs to be changed?
ok
Juan Blanco
@juanfranblanco
Dec 14 2018 09:49 UTC
well now you need to make sure the transaction is for the same function you are trying to decode
if you are testing internally, just get the transaction receipt and use the same transaction hash
Lyon.Nee
@LyonNee
Dec 14 2018 09:50 UTC
ok
Juan Blanco
@juanfranblanco
Dec 14 2018 09:51 UTC
foreach (var result in results) <-
just test with one hash
obviously you should be able to handle when you are trying to decode an incorrect transaction as you have seen
Lyon.Nee
@LyonNee
Dec 14 2018 09:51 UTC
ok .I will try the input parameters of transfer back now
I was successful
thanks
Juan Blanco
@juanfranblanco
Dec 14 2018 09:56 UTC
awesome!
Lyon.Nee
@LyonNee
Dec 14 2018 09:57 UTC
I will try the input parameters of setAllocation back now
I failed
Juan Blanco
@juanfranblanco
Dec 14 2018 10:02 UTC
is it the same transaction?
Lyon.Nee
@LyonNee
Dec 14 2018 10:03 UTC
no
0xbb004c896d6ccb71b90ee5913a8456ff9f455a0cf1bbe7ef8ad69c30fa94b33b Txhash
Juan Blanco
@juanfranblanco
Dec 14 2018 10:04 UTC
if you use the extension GetData() on both functions can you paste it here
so what is that txn hash from (what chain ?)
Lyon.Nee
@LyonNee
Dec 14 2018 10:05 UTC
The male chain
Juan Blanco
@juanfranblanco
Dec 14 2018 10:08 UTC
can you set the parameters from uint to uint256
also
times and balances
should be List<BigInteger>
Lyon.Nee
@LyonNee
Dec 14 2018 10:11 UTC
ok
I was successful
Juan Blanco
@juanfranblanco
Dec 14 2018 10:13 UTC
excellent :)
Lyon.Nee
@LyonNee
Dec 14 2018 10:13 UTC
thank you very mach!!!
Juan Blanco
@juanfranblanco
Dec 14 2018 10:13 UTC
my pleasure
Lyon.Nee
@LyonNee
Dec 14 2018 10:14 UTC
^o^
Raúl
@rsantirso
Dec 14 2018 10:19 UTC
So if you are using different programs, processes the best thing is to use different accounts per process, or have a nonce provider microservice for the accounts
@juanfranblanco , I agree with that and my tests are aware and can deal with it. The main problem is I can't figure out why ,after a completed transaction, a CallAsync fails when it reaches a 'require' statement and it success after several retries.
Juan Blanco
@juanfranblanco
Dec 14 2018 10:22 UTC
so I guess that is depending on the state of the contract
and you have got the transaction receipt
correct?
Raúl
@rsantirso
Dec 14 2018 10:55 UTC
Correct
Juan Blanco
@juanfranblanco
Dec 14 2018 11:12 UTC
what client are you using?
RevVivek
@RevVivek
Dec 14 2018 11:20 UTC

@juanfranblanco

I have one problem when I do sign with a transaction with nethereum trezor. It works fine. Then why there is problem with web3. It gives me invalid sender error

Juan Blanco
@juanfranblanco
Dec 14 2018 11:47 UTC
what web3?
does the recovery work ok in Nethereum?
Juan Blanco
@juanfranblanco
Dec 14 2018 11:52 UTC
or does the signature match?
 var accountNethereum = new Account("0x2e14c29aaecd1b7c681154d41f50c4bb8b6e4299a431960ed9e860e39cae6d29");
                accountNethereum.TransactionManager.Client = new RpcClient(new Uri("http://localhost:8545"));
                var signatureNethereum = await accountNethereum.TransactionManager.SignTransactionAsync(tx);
                System.Console.WriteLine("Trezor: " + signature);
                System.Console.WriteLine("Nethereum: " + signatureNethereum);
as i have not implemented the GetPublicKey for recovery
Raúl
@rsantirso
Dec 14 2018 12:19 UTC
what client are you using?
I'm using geth
William Adomako
@Lordwilliamsr_twitter
Dec 14 2018 14:11 UTC
I have been really trying to follow the nethereum events and logs conctract example code(multplier) and I keep getting null values, but when I test the contract in Remix the logs show values I am not really sure what i am doing wrong in visual studio. trying first to figure out how to post my code here
Juan Blanco
@juanfranblanco
Dec 14 2018 14:12 UTC
@Lordwilliamsr_twitter i recommend you to have a look at this docs
although the principles are the same
William Adomako
@Lordwilliamsr_twitter
Dec 14 2018 14:15 UTC
Thanks Juan, not sure I have seen this one yet, let me get to it right away :)
Juan Blanco
@juanfranblanco
Dec 14 2018 14:15 UTC
ah you can also run that as a Xamarin Workbook
William Adomako
@Lordwilliamsr_twitter
Dec 14 2018 14:48 UTC
var contractAddress = receipt.ContractAddress;
Juan Blanco
@juanfranblanco
Dec 14 2018 14:49 UTC
yeah
that is the address after deployment
of the smart contract
William Adomako
@Lordwilliamsr_twitter
Dec 14 2018 14:49 UTC
Hi Juan I am having a hard time declaring balances in Vscode, what type is it?
Juan Blanco
@juanfranblanco
Dec 14 2018 14:50 UTC
oh if you are creating the smart contract
William Adomako
@Lordwilliamsr_twitter
Dec 14 2018 14:50 UTC
yea I need to create the contract and compile it to get the abi and byte code
unless I am terribly missing something here :(
Juan Blanco
@juanfranblanco
Dec 14 2018 14:51 UTC
oh
public static string BYTECODE = "0x60606040526040516020806106f5833981016040528080519060200190919050505b80600160005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005081905550806000600050819055505b506106868061006f6000396000f360606040523615610074576000357c010000000000000000000000000000000000000000000000000000000090048063095ea7b31461008157806318160ddd146100b657806323b872dd146100d957806370a0823114610117578063a9059cbb14610143578063dd62ed3e1461017857610074565b61007f5b610002565b565b005b6100a060048080359060200190919080359060200190919050506101ad565b6040518082815260200191505060405180910390f35b6100c36004805050610674565b6040518082815260200191505060405180910390f35b6101016004808035906020019091908035906020019091908035906020019091905050610281565b6040518082815260200191505060405180910390f35b61012d600480803590602001909190505061048d565b6040518082815260200191505060405180910390f35b61016260048080359060200190919080359060200190919050506104cb565b6040518082815260200191505060405180910390f35b610197600480803590602001909190803590602001909190505061060b565b6040518082815260200191505060405180910390f35b600081600260005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005060008573ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905061027b565b92915050565b600081600160005060008673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050541015801561031b575081600260005060008673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005060003373ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000505410155b80156103275750600082115b1561047c5781600160005060008573ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828282505401925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a381600160005060008673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282825054039250508190555081600260005060008673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005060003373ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828282505403925050819055506001905061048656610485565b60009050610486565b5b9392505050565b6000600160005060008373ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000505490506104c6565b919050565b600081600160005060003373ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050541015801561050c5750600082115b156105fb5781600160005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282825054039250508190555081600160005060008573ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828282505401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905061060556610604565b60009050610605565b5b92915050565b6000600260005060008473ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005060008373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005054905061066e565b92915050565b60006000600050549050610683565b9056";
:)
Mainly if you run step by step the documentation we create a contract definition
each class is either the constructor (which includes the bytecode) as above
functions or events
William Adomako
@Lordwilliamsr_twitter
Dec 14 2018 14:54 UTC
ah thnx I have so much more to learn
for code generation
it will simplify it afterwards
William Adomako
@Lordwilliamsr_twitter
Dec 14 2018 16:46 UTC

Many thanks. I am wondering why there isnt a Task for "MineAndGetReceiptAsync" in the example u showed me which I am working on now, is it an assumption I already have it or?

Secondly, I get an error stating "TokenAmount" isnt defined in "Transferfunction" but I see it defined as:
public System.Numerics.BigInteger TokenAmount { get; set; }

Not really sure about that

Juan Blanco
@juanfranblanco
Dec 14 2018 16:59 UTC
yes newer samples don't mine anything as it is assumed that node is mining already
there are new testchains that use PoA / Clique which are much faster than mining PoW
William Adomako
@Lordwilliamsr_twitter
Dec 14 2018 17:01 UTC
No Worries I just misunderstood that, I am running through my own test chain, so I will just include now
Juan Blanco
@juanfranblanco
Dec 14 2018 17:01 UTC
these are the testchains https://github.com/Nethereum/TestChains
William Adomako
@Lordwilliamsr_twitter
Dec 14 2018 17:04 UTC
Do you by any chance know why TokenAmount is throwing an error? that it is not defined in TransferFunction?
image.png
it is in there, not sure what I am missing :(