Reputation: 1
ERROR: raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=7545): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6e001a6400>: Failed to establish a new connection: [Errno 111] Connection refused'))
import json
import solcx
from solcx import compile_standard
from web3 import Web3
with open("./SimpleStorage.sol","r") as file:
simple_storage_file= file.read()
''' print(simple_storage_file) '''
compiled_sol = compile_standard(
{
"language": "Solidity",
"sources":{"Simplestorage.sol":{"content":simple_storage_file}},
"settings":{
"outputSelection":{
"*":{"*":["abi","metadata","evm.bytecode","evm.sourceMap"]}
}
},
},
solc_version="0.6.0",
)
with open("compiled_code.json","w") as file:
json.dump(compiled_sol,file)
bytecode = compiled_sol["contracts"]["Simplestorage.sol"]["Simplestorage"]["evm"][
"bytecode"
]["object"]
#get abi
abi=compiled_sol["contracts"]['Simplestorage.sol']["Simplestorage"]["abi"]
w3 = Web3(Web3.HTTPProvider("HTTP://127.0.0.1:7545"))
chain_id = 5777
my_address = "0xd8001711E3F781D3c762fF2D5e10504CE3033240"
private_key ="0x0ed2c7e46aab218aa085032d315c16d32c0215dd60f0122810378fc636370ff4"
Simplestorage = w3.eth.contract(abi=abi, bytecode=bytecode)
nonce = w3.eth.getTransactionCount(my_address)
print(nonce)
Upvotes: 0
Views: 51
Reputation: 189
First of all, don't post your Private Key online.
If you wanna test your contract locally, then you will have to have a local test net running.
If you wanna deploy your contract to any network, replace the RPC url with the chain's RPC url.
Upvotes: 0