These are chat archives for Nethereum/Nethereum

25th
Jul 2017
王維靖
@weijing329
Jul 25 2017 09:18

Hello All, I am using Nethereum v2.0.0-rc5 to deploy solidity contracts asynchronously into private blockchain, and running into problem, can someone help me?

My test scenario is to deploy 20 contracts with the same abi, bytecode, but with different constructor parameters.
Geth is mining constantly, all contracts are deployed using the same unlocked account.
In my application, I make all solidity transaction call triggered by rabbitmq message consumer uses the same Web3Geth client instance inside a singleton class.

With above settings, everything works fine when I wait for each transaction and its receipt with await keyword:

string tx_hash = await web3geth.Eth.DeployContract.SendRequestAsync(...).ConfigureAwait(false);

await BackgroundWaitTransactionResult(tx_hash).ConfigureAwait(false);

However if I remove await keyword, sending all transaction call without waiting for its receipt, this will cause problem:
some transaction's input is null, even though in the application log it seems every constructor parameters are passed to DeployContract.SendRequestAsync() function

string tx_hash = await web3geth.Eth.DeployContract.SendRequestAsync(...).ConfigureAwait(false);

// fire and forget
BackgroundWaitTransactionResult(tx_hash).ConfigureAwait(false);
// geth console
> eth.getTransaction(tx_hash)
null
>
Juan Blanco
@juanfranblanco
Jul 25 2017 09:24
have you checked the transaction queue in geth?
they may have not been mined yet
@weijing329
王維靖
@weijing329
Jul 25 2017 09:33

I also run the test with embark framework's automine script

INFO [07-25|17:01:57] Submitted contract creation              fullhash=0x914d35511e8d4ee0f7a5b9bcde271f6a381b2addea05e563f8649d4f0d26c1ce contract=0xddbc65177b36011b6a16f0761e786de970e1741b
== Pending transactions! Looking for next block...
INFO [07-25|17:01:58] Updated mining threads                   threads=0
INFO [07-25|17:01:58] Transaction pool price threshold updated price=18000000000
INFO [07-25|17:01:58] Starting mining operation
INFO [07-25|17:01:58] Commit new mining work                   number=1538 txs=1 uncles=0 elapsed=2.03ms
INFO [07-25|17:02:01] Successfully sealed new block            number=1538 hash=f07aba…3c428d
INFO [07-25|17:02:01] 🔗 block reached canonical chain          number=1533 hash=437b48…89afb3
INFO [07-25|17:02:01] 🔨 mined potential block                  number=1538 hash=f07aba…3c428d
INFO [07-25|17:02:01] Commit new mining work                   number=1539 txs=0 uncles=0 elapsed=1.327ms
== No transactions left. Stopping miner...

There is no pending transaction left, so I think it's mainly because of null transcation. However I am not sure what cause the problem.

Juan Blanco
@juanfranblanco
Jul 25 2017 09:42
Are you sending the 20 txn all at once?
thinking about nonces collitions
you could have your own nonce singleton counter
any errors?
王維靖
@weijing329
Jul 25 2017 09:46
ohh~ nonces collitions, I forgot about that.
王維靖
@weijing329
Jul 25 2017 09:58
I added try catch, but there is no error log output.
try
{
  var gas = new HexBigInteger(4700000);
  var wei = new HexBigInteger(0);
  string tx_hash = await web3geth.Eth.DeployContract.SendRequestAsync(
    abi: contract_abi,
    contractByteCode: contract_bytecode,
    from: sender_address,
    gas: gas,
    value: wei,
    values: new object[] {
      ...
    }).ConfigureAwait(false);

  return tx_hash;
}
catch (Exception ex)
{
  _logger.LogError("Exception {@ex}", ex);
  throw ex;
}
王維靖
@weijing329
Jul 25 2017 10:06
@juanfranblanco Thanks a lot for your help, I will try to fix nonces collisions problem in my code.
Juan Blanco
@juanfranblanco
Jul 25 2017 10:22
no bother :)
Thomas Conté
@tomconte
Jul 25 2017 15:15
Hi everyone, what is the latest way to sign a contract transaction offline ? I am using web3.OfflineTransactionSigner.SignTransaction() but not sure this is the most current ?
Currently calling: var encoded = web3.OfflineTransactionSigner.SignTransaction(userSecretKey, contractAddress, 0, txCount.Value, 1000000000000L, 900000, data);
But I get a pretty strange error: Error while unloading appdomain. (Exception from HRESULT: 0x80131015)
Juan Blanco
@juanfranblanco
Jul 25 2017 15:19
@tomconte it should be the same transaction signer
you can instantiate Web3 with an Account(privateKey) which will send the transaction for you
Thomas Conté
@tomconte
Jul 25 2017 15:20
@juanfranblanco ever seen that call crash? it seems to run for a fairly long time (a few seconds) and then crashes
Juan Blanco
@juanfranblanco
Jul 25 2017 15:20
no I haven't
in what environment are you?
WebApp?
Thomas Conté
@tomconte
Jul 25 2017 15:21
.NET 4.5.2, running in VS2017
Just a C# class library, called from unit test
Juan Blanco
@juanfranblanco
Jul 25 2017 15:23
oh.. what unit test framework?
Thomas Conté
@tomconte
Jul 25 2017 15:25
Just VS unit test project
Ahah... if I instantiate Web3 using an Account object it works
Juan Blanco
@juanfranblanco
Jul 25 2017 15:27
It works SendTransaction normally? or OfflineTransactionSigner
Thomas Conté
@tomconte
Jul 25 2017 15:28
OfflineTransactionSigner
Juan Blanco
@juanfranblanco
Jul 25 2017 15:28
well that does not have any dependencies with Account
mainly when you use the Account
with a private key
everytime you send a transaction will be signed offline (get the nonce etc) and send as a raw transaction
Thomas Conté
@tomconte
Jul 25 2017 15:30
Ah !
Juan Blanco
@juanfranblanco
Jul 25 2017 15:30
but the OfflineTransactionSigner is independent
that has been moved as a static helper on the next release (suggested by @knocte )
Thomas Conté
@tomconte
Jul 25 2017 15:31
OK so now that I am initializing Web3 with an Account I should be able to just send a transaction the 'normal' way and it will automatically be signed offline, correct ?
Juan Blanco
@juanfranblanco
Jul 25 2017 15:31
yes
Thomas Conté
@tomconte
Jul 25 2017 15:32
I will try this now. Sounds much easier ;-)
Juan Blanco
@juanfranblanco
Jul 25 2017 15:32
so if you point to infura (for example) it will just work without the need of geth
that is kind of an example
(simple as it is just doing a transfer, but it works the same for contracts)
@tomconte the above deploys a contract
and sends some transactions
Thomas Conté
@tomconte
Jul 25 2017 15:37
Perfect thanks !
Thomas Conté
@tomconte
Jul 25 2017 16:18
It works now, thanks again. Also I think I wasn't awaiting the calls properly in my unit test and it was causing the crash.
Y. Mutlu
@ymutluu_twitter
Jul 25 2017 18:21

@juanfranblanco I have add web3 toWei convert operation to my code. now error is : {"exceeds block gas limit"}

my code is :
var unlockAccountResult = web3.Personal.UnlockAccount.SendRequestAsync(senderAddress, password, 600).Result;
var val = web3.Convert.ToWei(new HexBigInteger("0.5"));
var txId = web3.Eth.Transactions.SendTransaction.SendRequestAsync(new TransactionInput()
{
From = senderAddress,
To = toAddress,
Value = new HexBigInteger(val)
}).Result;

do you have any idea?