2

I have deployed the simple datastorage example smart contract on mumbai testnet. I have the smart contract abi and address. I am trying to use web3 in my python code to interact with smart contract. But, I keep getting this error "ValueError: {'code': -32000, 'message': 'unknown account'}".

Below is my code:


import pprintpp
import web3
from web3 import Web3, HTTPProvider
from web3.middleware import geth_poa_middleware

w3 = Web3(HTTPProvider('<url>'))
w3.middleware_onion.inject(geth_poa_middleware,layer=0)

res = w3.isConnected()
print(res) // I get true as the result which means it is connected correctly right?



abi = [
    {
        "inputs": [
            {
                "internalType": "uint256",
                "name": "x",
                "type": "uint256"
            }
        ],
        "name": "set",
        "outputs": [],
        "stateMutability": "nonpayable",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "get",
        "outputs": [
            {
                "internalType": "uint256",
                "name": "",
                "type": "uint256"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    }
]
is_address_valid = w3.isAddress(<contract address>)
print(is_address_valid) // i get true when I run the code




c = w3.eth.contract(address=<contract address>,abi=abi)


rtnValue = c.caller().get()
print(rtnValue) // i get the correct current value

gas_estimate = c.functions.set(3).estimate_gas()
print(f'Gas estimate to transact with set func: {gas_estimate}')


if gas_estimate < 100000:
    print('Sending transaction to set(3)\n')
    tx_hash = c.functions.set(3).transact()
    receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
    print("Transaction receipt mined:")
else:
    print("Gas cost exceeds 100000")











TylerH
  • 20,799
  • 66
  • 75
  • 101
skr
  • 127
  • 2
  • 16

0 Answers0