It depends on how you have deployed your contract. If it was deployed correctly then you can call.
einstance.functions.getTime().call()
where einstance must be instance of web3._utils.datatypes.Contract.
Little brief on how to install your contract
Step1:
Compile your contract and get the bytecode and abi. You can install a specific version of sold compiler on your machine .
For abi
solc --abi test.sol
for bytecode
solc --bin test.sol
The instantiate by copying your abi and bytecode
Test = w3.eth.contract(abi=abi, bytecode=bytecode)
Then you have to deploy your contract, I did it on localchain
w3 = Web3("http://localhost:8545")
w3.eth.defaultAccount = w3.eth.accounts[0]
tx_hash = Test.constructor().transact()
tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
Your deployed contract
deployed = w3.eth.contract(
address=tx_receipt.contractAddress,
abi=abi
Now you can call the functions on your deployed contract by
deployed.functions.getTime().call()
>>>1585998887
I used this contract
pragma solidity 0.6.4;
contract Test {
function getTime() public view returns (uint){
return now;
}
}
Make sure your solc compiler (Installed on your machine) is same as in pragma statement.