1

I am learning solidity NFT, I am trying to generate v, r ,s using python web3

require(owner() == ecrecover(keccak256(abi.encodePacked(this, tokenId)), v, r, s), "owner should sign tokenId");

My python script

from web3.auto import w3
from eth_account.messages import encode_defunct

msg = "contractaddrsstokenid"
private_key = "mywalletprivatekey"
message = encode_defunct(text=msg)
signed_message =  w3.eth.account.sign_message(message, private_key=private_key)
print(signed_message)

it returns v, s, r and signature. But values are supported in contract, it says invalid format. i have changed to base64 and use. It fails with "owner should sign tokenId". How can i create v,s,r using python web3.

1
  • Is the private key from the contract's owner? Can you show an example of the message to be signed? What's tokenId type? uint256, bytes32, ...
    – Ismael
    Commented Sep 5, 2021 at 18:01

1 Answer 1

2

Seems like your private key is "mywalletprivatekey". Private keys shall be hexadecimal (only hex chars) and 64 chars long !

Using private_key = "4d9e599423f0a37115c35f1dc4b749a4754545e4172d3901260a484512eee4d6" (this dont hold any ether) shall work !

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.