web3 6.12.0 solc-v0.8.23 Python 3.12.1 Ganache v2.7.1
I've deployed this contract:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract TestContract {
address public myAddress;
uint testNumber;
constructor() {
myAddress = tx.origin;
testNumber = 444;
}
function testTest() public view returns (address, uint) {
uint a = 22 + 33;
return (tx.origin, a);
}
}
Now I want to call fuction testTest() from my terminal using python. Here is my python code:
from web3 import Web3
def test(_abi, _contract_address):
my_address = "" # ganache address
private_key = "" # ganache private key
abi = _abi # contracts abi
contract_address = _contract_address # contracts address
# connect to contract
w3 = Web3(Web3.HTTPProvider("HTTP://127.0.0.1:7545"))
nonce = w3.eth.get_transaction_count(my_address)
contract = w3.eth.contract(address=contract_address,abi=abi)
print(contract.functions.testTest().call())
# this gives 0x0000000000000000000000000000000000000000
# and number 55
print(contract.functions.myAddress().call())
# this gives legit ganache address e.g.
# 0x13997C24536d6266B871B6478e803F186F3B6ffD
test([...],"0xdwed...")
testTest() function should return my_address but it doesn't. Can me someone explain me why ganache EVM can't read tx.origin or msg.sender. It looks like my contract can't access its own context after have been deployed. Am I using web3.py in a wrong way?