I have a solidity function for verify signature with nonce. How to make eligible (for mint on my way) addresses with function like this?

function isValidSignature(
    uint128 nonce,
    bytes memory signature
) view internal returns (bool) {
    bytes32 data = keccak256(abi.encodePacked(address(this), _msgSender(), nonce));//
    return signer == data.toEthSignedMessageHash().recover(signature);

I am already have tried solutions from chatgpt but it is doesnt work

def get_valid_signature(nonce):
 account = Account.from_key(private_key)  # приватный ключ соответствующий signer
 data = w3.solidity_keccak(['address', 'address', 'uint128'], [Web3.to_checksum_address(signer), Web3.to_checksum_address("0x54C32309b67e72bD44899e46EC630d14Eb96125f"), nonce])
 data_bytes32 = w3.to_bytes(data)
 signature = account.signHash(data_bytes32)
 return signature.signature

1 Answer 1


It seems like you're trying trying to implement a function in Solidity that verifies a signature along with a nonce. However, the code appears to be a mix of Solidity and Python/Web3.js, which is confusing.

Firstly, the line return signer == data.toEthSignedMessageHash().recover(signature); seems to conflate different layers of the tech stack. The .toEthSignedMessageHash() and .recover() methods are generally parts of Web3.js or Ethers.js and are not native to Solidity.

To answer the main question, it is entirely possible to compare two variables using == in a return statement in Solidity. However, the correct way to do this in Solidity would involve using ecrecover to recover the address from the signature, and then comparing that to signer.

However, without the full context or complete code, it's difficult for me to understand the variables you're assigning. If you could clarify the technologies they are using and provide more complete code samples, that would enable a more accurate solution.

Best Regards, X

  • Check this contract arbiscan.io/address/… I want do sig verif like here
    – lang.eth
    Aug 29, 2023 at 7:34
  • Why are you using saying that toEthSignedMessageHash, recover are there to conflate different layers of the tech stack? They are part of OpenZepplin cryptography solidity library docs.openzeppelin.com/contracts/2.x/api/cryptography. Please, don't use chaptgpt to answer question if you don't know about the subject.
    – Ismael
    Aug 31, 2023 at 3:03

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.