I just want to use ecrecover to verify with a public key that the corresponding private key signed a message passed through a variable in solidity. What's the simple way to do this? I have inserted ??? into my solidity where I don't know how to use ecrecover.

ie: client end:

message: "solidity has poor documentation"

bob's private key: "2j3940"

bob's public key: "0x3jhr32"

signed message: "3cj0239roi3409i34234"

solidity end:

function verifyMessage(message, signedMessage, publicKey){

    bool verified = False;

    if (????){
        verified = True;


expected use:

verifyMessage("solidity has poor documentation","3cj0239roi3409i34234","0x3jhr32")


Here is another question talking about the same issue, but I am unable to use their implementation: Verification of externally-created ECDSA signatures

1 Answer 1


Check out Openzeppelin ECDSA: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/ECDSA.sol. They have a recover function where you can input the signature as a string.

// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;

import {ECDSA} from "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/ECDSA.sol";

contract MySignatureTest {
    using ECDSA for bytes32;
    function verifyMessage(bytes32 messageHash, bytes memory signedMessage, address account) external pure returns (bool) {
        return messageHash
            .recover(signedMessage) == account;

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.