0
//Error: Given parameter is not bytes: "0xue"
//let a = true

myContract.methods.functionName(a).send({
    from: result[0],
    gas: 4700000,
}).then((result) => {
    console.log(result)
})
.catch((error) => {
    console.log(error)
})

my web3 version is 1.0.0.beta.35

  • looks like you have an extra } after console.log(result). Please share these: your contract method functionName signature ( it's from your contract, right? ) , and exact send argument values, i.e. what's in result[0] – Utgarda Sep 26 '18 at 12:59
  • result[0] will be the account address. here functionName(a) should get bytes32 values as input. If it gets other than bytes32 web3 is throwing the error Given parameter is not bytes. I am not able to capture the following error in the catch – MallRoy Sep 26 '18 at 13:26
1

The way you're catching now is lets you catch exceptions from async calls, i.e. when .send({from...}) returns you a promise. But if functionName gets a wrong parameter, the remote call doesn't even start, so you need to catch it differently.

Try this:

try {
    myContract.methods.functionName(a).send({
        from: ...
    }).then((result) => {
        console.log(result)
    })
} catch(err) {
   //process the argument-related error here
}

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.