[Ethereum] generate signmessage in python web3

nftpythonsolidityweb3.py

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.

Best Answer

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 !

Related Topic