2

I'm trying to create a transaction with Nethereum as below but I cant see the result anywhere. I've checked the wallet and queried from custom client.

var proposalsFunction = contract.GetFunction("newProposal");
var transactionOfProposal = await proposalsFunction.SendTransactionAsync( addressFrom,p.Recipient,p.Amount,p.Description,true);

This is the contract method I'm trying to execute. (For some reason it wants bool as the last parameter)

 function newProposal(
    address beneficiary,
    uint etherAmount,
    string JobDescription,
    bytes transactionBytecode
)
    onlyMembers
    returns (uint proposalID)
{
... 
}

This is how it looks in geth primary node. I can see the tx in sub nodes as well. So the tx is there somewhere but what happened? enter image description here

2
  • Did you solved this? Did you mine the transaction? Ater enable mining did you try to get the transaction receipt? Commented Jul 31, 2016 at 7:30
  • I did mine it and I could see the tx on all nodes (in the console) but the proposal would not show in chain. However, by sending gas it finally worked.
    – mechanicum
    Commented Aug 1, 2016 at 7:33

2 Answers 2

1

Your main issue is that you have ran out of gas.

Execution of contracts requires "gas", in this scenario you have not provided enough gas, and all of it has been consumed. Contracts depending on their complexity use different amounts of gas, the gas is calculated per instruction.

A commmon way to validate this is to check if the gas is the same as the gas used

TransactionSource.Gas == TransactionReceipt.GasUsed

If using geth as a client you can examing the stacktrace and find the error, first you can get the debug information:

await Web3.DebugGeth.TraceTransaction.SendRequestAsync(transactionHash,
                    new TraceTransactionOptions {DisableMemory = true, DisableStorage = true, DisableStack = true});        

and then use the following functions to validate this:

    public bool HasError(JObject stack)
    {
        return !string.IsNullOrEmpty(GetError(stack));
    }

    public string GetError(JObject stack)
    {
        var structsLogs = (JArray)stack["structLogs"];
        if (structsLogs.Count > 0)
        {
            var lastCall = structsLogs[structsLogs.Count - 1];
            return lastCall["error"].Value<string>();
        }
        return null;
    }

This helper class is included from RC5. So you can do the following:

web3.DebugGeth.StackErrorChecker.HasError("stacktrace");

You can calculate the gas beforehand by doing something like:

var gas = await multiplyFunction.EstimateGasAsync(69);


Bytes issue, a bool convertor was configured instead of a bytes one, this is fixed from RC5.


Await and slow response, this has nothing to do with using the keyword await. Mainly the transaction is taking a long time, the cause for this might be due to not being fully synchronised. The right nonce needs to be used for the transaction and it might be awaiting (geth) to have this information.

You would not be able to get a receipt without the transactionId, if not await keyword is in place you will be assigning to a variable the Task object.

7
  • You were correct, main thing is a gas issue but the other problem remains. I cant get the transaction Info because the app gets stuck in the function line await proposalsFunction.SendTransactionAsync(AccountHelper.AddressFrom,...). Same thing happens in this as well: await Web3.Personal.UnlockAccount.SendRequestAsync(AddressFrom, ...);
    – mechanicum
    Commented Aug 1, 2016 at 11:43
  • Btw, is there a way to know the exact gas requirements beforehand like in the wallet so I can send that specific amount. Also what is the value field for?
    – mechanicum
    Commented Aug 1, 2016 at 11:56
  • Value is the amout of ether you want to send to an address (can be a contract) Commented Aug 1, 2016 at 12:42
  • What are you usig RPC or IPC? have you got all flags enabled? personal, eth etc? Commented Aug 1, 2016 at 12:44
  • You have eth_estimateGas rpc call that you can use passing it the transaction. Ill create in web3 a simple method for this. Commented Aug 1, 2016 at 12:47
0

I'm putting this here because it answers the original question but I will accept any other answer that goes in depth about the below issues.

I'm not truly sure how this worked but sending gas and a value(?) was the answer.

var transactionOfProposal = proposalsFunction
                .SendTransactionAsync(addressFrom, new HexBigInteger(232805),
                new HexBigInteger(1), p.Recipient, p.Amount, p.Description, false);

Things I still don't understand are;

  • When I started the miners, I didn't set a minimum accepted level or something so I don't understand why the tx would be ignored even though its visible on all node consoles.
  • The last parameter of the contract function is a byte[] so why does it insist on bool I don't understand.
  • I can't put await before the part starting with proposalsFunction because when I add await, the function never returns. At least not for the 20 mins I waited and most certainly not after all confirmations are done. It takes at most a minute for other transactions.

I was planning to use something like below to get a receipt.

while (receiptTransaction == null)
{
       receiptTransaction = await transactions.GetTransactionReceipt.SendRequestAsync(transactionOfProposal);
       await Task.Delay(1000);
}
6
  • Hi, the issue you have is that you ran out of gas, the trasaction was valid, but it will have error due to not having enough gas. Commented Aug 1, 2016 at 9:21
  • Your issue with the transaction not being returned is really strange, transactions are instant. What are you using RPC or IPC? Commented Aug 1, 2016 at 9:24
  • You can find out if you have ran out of gas normally if the gas used = the gas sent. Or if using debug the last element is is an error. I will expand further with an answer. Commented Aug 1, 2016 at 9:26
  • On the bytes issue it is a bug.. it should be out in an emergency release in a few hours. Commented Aug 1, 2016 at 9:35
  • Regarding the transaction not being sent, have you fully sync your wallet? It might be waiting.. Commented Aug 1, 2016 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.