How can I use caver.ecrecover to get the public key of the transaction signer?

I am using caver 1.4.1

A full example is in the fiddle, but in short I’m trying to get the public key like this

const transaction = await caver.klay.getTransactionReceipt(transactionReceipt.transactionHash)
const {V, R, S} = transaction.signatures[0];
const params = [transaction.transactionHash, V, R, S];
const publicKey = await caver.klay.ecRecover(...params);

,but I keep getting the error Uncaught (in promise) Error: Returned error: Error: Invalid signature length

Hi,

ecRecover is for signed message, not transaction.
You can use caver.klay.recoverTransaction. Please see the Klaytn docs.

1 Like