-
import json
from web3 import Web3
from solcx import compile_standard, install_solc
install_solc("0.6.0")
with open("./SimpleStorage.sol", "r") as file:
simple_storage_file = file.read()
compiled_sol = compile_standard(
{
"language": "Solidity",
"sources": {"SimpleStorage.sol": {"content": simple_storage_file}},
"settings": {
"outputSelection": {
"*": {"*": ["abi", "metadata", "evm.bytecode", "evm.sourceMap"]}
}
},
},
)
with open("compiled_code.json", "w") as file:
json.dump(compiled_sol, file)
# get bytecode
bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["evm"][
"bytecode"
]
["object"]
# get abi
abi = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["abi"]
# connect to ganache
w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:7545"))
chain_id = 5777
my_address = "0x321E3ed12C6a6DB0467f2402e051723C5f9a85F7"
private_key = "0x2387a4a564373b946aa24092dec2305ae3f4fdd414649bb82033323a21b72a64"
# create ganache contract
SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)
# get latestest transaction
nonce = w3.eth.getTransactionCount(my_address)
print(nonce)
# 1- build transaction
# 2- sign transaction
# 3- send transaction
transaction = SimpleStorage.constructor().buildTransaction(
{"chainId": chain_id, "from": my_address, "nonce": nonce}
)
print(transaction) the snippet of what seems to be the issue, it points to line 44, which l highlighted in the second half of the error, but after comparing the code to what is posted all seems fine( code above). Not sure what I'm doing wrong here.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
What was the command you used to have a ganache chain running locally on port 7545? ALSO, PLEASE MAKE SURE THERE ARE NO "REAL" FUNDS ASSOCIATED WITH THAT PRIVATE KEY. Odd suggestion... but maybe we could try on python 3.9... |
Beta Was this translation helpful? Give feedback.
-
Update: it looks like my VPN was the culprit, I rebuilt the code from top to bottom and bypassed VS code. I was able to print I use private internet access as a VPN client. |
Beta Was this translation helpful? Give feedback.
Update: it looks like my VPN was the culprit, I rebuilt the code from top to bottom and bypassed VS code. I was able to print
<class 'web3._utils.datatypes.Contract'> after this. Not sure if it was an error in my code.
I use private internet access as a VPN client.