1

We have developed a simple Smart Contract which offers this following public transaction method:

function bid(uint256 _userCode, uint256 _amount) public {

        assert(_userCode> 0);
        assert(_amount> 0);

        winningBid.userCode= _userCode;
        winningBid.amount= _amount;

        var bidData= Bid(_userCode, _amount);
        bids.push(bidData);
    }

We are sending the transaction using this Nethereum code:

var result = bidFunction.SendTransactionAndWaitForReceiptAsync(address, gas, balance, null, userCode, amount).Result;

The method invocation does not throw any exception, even passing 0 to the userCode that, if you take a look to the Smart Contract, should trigger the assert and stop the method execution.

How could we check if a transaction has completed correctly or has been rejected by some assert check?

marked as duplicate by Ismael, gisdev_p, Richard Horrocks, Malone, eth Nov 26 '17 at 12:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Does the function include a parameter for a callback function? This is usually how it is done. – jojeyh Nov 24 '17 at 13:22
  • We are not using any callback function. Could you please provide an example? – systempuntoout Nov 24 '17 at 13:24
  • Since byzantinum the recipt includes a field status to indicate if the transaction was executed correctly or not. – Ismael Nov 25 '17 at 4:25
0

Reading the Solidity docs on error handling, these things come to mind:

  • You should use require instead of assert. Assert is for detecting bugs in the code. Require is for aborting operation on invalid input (your use case).

  • Solidity will revert the whole operation, when it encounters assert or require and nothing will be changed.

  • Catching exceptions is not yet possible.

  • You could make your function return the accepted value, e.g.:

    function bid(uint256 _userCode, uint256 _amount) public constant returns (uint256) {
    
        assert(_userCode> 0);
        assert(_amount> 0);
    
        winningBid.userCode= _userCode;
        winningBid.amount= _amount;
    
        var bidData= Bid(_userCode, _amount);
        bids.push(bidData);
    
        return _amount;
    }
    

    It should be possible to tell the difference between a successful call and a failed one, right?

  • Thanks for your answer. Since the bid function is a transaction (it's changing the blockchain state) you can't read the transaction return value via Nethereum SDK; all you can get is a receipt. – systempuntoout Nov 24 '17 at 16:10

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