0

So I have this solidity function:

function claimGoodTest(uint256 typeId) public payable {
    if (msg.value < 4000) revert();
}

I test it with the following:

var result = await contract.claimGoodTest(typeId, {
    from: accounts[0], value: web3.utils.toWei('40', 'ether')
}, function(result) { })

I get this :

Error: VM Exception while processing transaction: revert

Why is this happening ? This seems like a bug or I have the wrong syntax.

  • If you comment out the if (msg.value < 4000) revert(); line, do you still see a problem? (I'm trying to narrow down whether it's that line causing the revert.) – smarx Jan 13 '18 at 17:19
  • May be you should try: if (msg.value < 4000) { revert(); } – Roman Frolov Jan 13 '18 at 17:20
  • If i comment out that line then there is no revert and the function works. If i add curly braces there is no effect. Perhaps my syntax on the JS side is wrong ? – admazzola Jan 13 '18 at 17:39
  • I can't reproduce this... could you share the code for how you instantiate contract? – smarx Jan 13 '18 at 18:30
  • Which version of web3 are you using? – Adam Kipnis Jan 13 '18 at 18:52
0

Oh! I just had to switch the order of the test parameters. The object with value should be the very last param. The callback needed to be the second to last. This is not documented well.

var result = await contract.claimGoodTest( typeId , function(){} ,{ value:web3utils.toWei('0.00001','ether') })

  • Is contract a Truffle thing? The syntax you're using doesn't match up with web3.js 1.0.0, which uses promises instead of callback functions. web3.js 0.2x.x would have had the callback function as the last parameter. So contract must be something else, and I'm guessing Truffle? – smarx Jan 13 '18 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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