1

I have a contract that is doing an ecrecover:

function recover(bytes32 h, uint8 v, bytes32 r, bytes32 s) public returns (address) {                
      return ecrecover(h, v, r, s);
}

It works fine in my truffle unit tests

console.log(await ecdsa.recover.call('0xbec921276c8067fe0c82def3e5ecfd8447f1961bc85768c2a56e6bd26d3c0c53', '0x1b', '0x6c5b9b4deb51a4733784657abac3e1dcef04086979a500397456b948981ccbc1', '0x2944200fb10074295baa04db6c048dc120ee9f3b48a42cbe4223242f07cc8e85')); 

But when I use [email protected] and the contract ABI in NodeJs I receive an error:

const contract = new this.web3.eth.Contract(this.abi.abi, this.abi.networks['5777'].address);    
await contract.methods.recover.call('0xbec921276c8067fe0c82def3e5ecfd8447f1961bc85768c2a56e6bd26d3c0c53', '0x1b', '0x6c5b9b4deb51a4733784657abac3e1dcef04086979a500397456b948981ccbc1', '0x2944200fb10074295baa04db6c048dc120ee9f3b48a42cbe4223242f07cc8e85', (err, result) => { console.log(err); console.log(result);});


{ Error: types/values length mismatch (count={"types":4,"values":0}, value={"types":[{"name":"h","type":"bytes32"},{"name":"v","type":"uint8"},{"name":"r","type":"bytes32"},{"name":"s","type":"bytes32"}],"values":[]}, version=4.0.27)

1 Answer 1

0

With web3 v1 you should pass the parameters with the method and not call (https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#methods-mymethod-call).

Something like this should work

await contract.methods.recover(
    '0xbec921276c8067fe0c82def3e5ecfd8447f1961bc85768c2a56e6bd26d3c0c53', 
    '0x1b', 
    '0x6c5b9b4deb51a4733784657abac3e1dcef04086979a500397456b948981ccbc1', 
    '0x2944200fb10074295baa04db6c048dc120ee9f3b48a42cbe4223242f07cc8e85'
).call((err, result) => { 
    console.log(err); 
    console.log(result);
});

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.