Following is the smart contract code, setMessage method always fail with revert while estimating gas using web3.py, even when the address user is same as msg.sender. when the contract is deployed on Ganache [windows application] and the transaction is build using web3.py "buildTransaction" method, the revert statement error is always returned while estimating the Gas for transaction. can someone please suggest what is the issue with this code?
''' pragma solidity ^0.8.13; contract EchoMyName { address owner; string message = "EchoMyName world";
function setMessage( string memory msg_ , address user) public
{
if( msg.sender == user)
{
message = msg_;
}
else
{
revert("Sorry");
}
}
function getMessage() public view returns ( string memory )
{
return message;
}
constructor()
{
owner = msg.sender;
}
} '''
Python Code is below:
contract_func = contract.functions.setMessage("Hello There", "0x4628df168f80c9BE779c0dC1aBaC36b070F662AC")
transaction = contract_func.buildTransaction(transaction = {'nonce' : nonce,'gasPrice': w3.eth.gas_price})
This is the Exception Returned, even if the message sender and user Address is same, and Test Ethers are also in account:
Exception: execution reverted: VM Exception while processing transaction: revert Sorry