2

I am able to use ecRecover to verify the signer in Javascript, for example:

const ecRecoverAddr = await window.ethereum.request({
    method: "personal_ecRecover",
    params: [message, signedMessage],
});

However, when I try the following Python code:

from web3 import Web3, HTTPProvider

def verify(request, message, signedMessage):
    response = web3.geth.personal.ecRecover(message, signature)
    return HttpResponse(response, content_type='text/json')

I get this error: name 'web3' is not defined

Does this mean that I need to instantiate some sort of provider for web3? What should be done?

Is there a way to retrieve the public key using ecRecover without the use of a provider?

Shouldn't it just be a method that can run without any connections?

Thanks!

1 Answer 1

1

You will need to instantiate the web3 object and cannot refer to a package here.

from web3 import Web3, HTTPProvider

w3 = Web3(Web3.HTTPProvider(<infura or alchemy URL>))

def verify(request, message, signedMessage):
    response = w3.geth.personal.ecRecover(message, signature)
    return HttpResponse(response, content_type='text/json')
2
  • 1
    For anyone else who may come across this post, use w3.eth.account.recover_message instead of the incorrect w3.geth.personal.ecRecover. The signedMessage that I have comes from Web3.js, and is in the form 0xb47b9215304122fe5ae23aa6e89d9f01c8497fbeb903b8e8602e2db3d235c8af3f6b8fee791019045f44fe61dd9af193e3d241b108311893d1db852dc7d76d811c however, when I try to pass that to w3.eth.account.recover_message in Python, I get the following error: 'str' object has no attribute 'version'. What do I need to do?
    – dx1
    Commented Oct 7, 2021 at 2:25
  • @dx1 I recommend to create a new question for that issue.
    – Ismael
    Commented Oct 8, 2021 at 17:44

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.