Lesson 4: Error message using chain_id in buildTransaction() #650
Answered
by
selinimsibiri
selinimsibiri
asked this question in
Q&A
-
Hello _from solcx import compile_standard, install_solc
import json
from web3 import Web3
with open("./SimpleStorage.sol", "r") as file:
simple_storage_file = file.read()
print("Installing...")
install_solc("0.6.0")
# Solidity source code
compiled_sol = compile_standard(
{
"language": "Solidity",
"sources": {"SimpleStorage.sol": {"content": simple_storage_file}},
"settings": {
"outputSelection": {
"*": {
"*": ["abi", "metadata", "evm.bytecode", "evm.bytecode.sourceMap"]
}
}
},
},
solc_version="0.6.0",
)
with open("compile_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"]
# for conneting to ganache
w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:7545"))
chain_id = 1337
my_address = "0x66487dD584Ed8bB02064f2d855659882a5772134"
private_key = "0xe02ab2b4fddde5ba4ec22fc971359983e2687b21cf30544d85ab2991080aec13"
# create the contract in python
SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)
# print(SimpleStorage)
# get the latest transactions
nonce = w3.eth.getTransactionCount(my_address)
print(nonce)
# 1.build a transaction
# 2.Sign a transaction
# 3.Send a transaction
transaction = SimpleStorage.constructor().buildTransaction(
{"chainId": chain_id, "from": my_address, "nonce": nonce}
)
# print(transaction)_
and here is the thing i have no idea what it is:
Can you help me please? |
Beta Was this translation helpful? Give feedback.
Answered by
selinimsibiri
Dec 29, 2021
Replies: 1 comment 2 replies
-
i uninstalled web3 and installed web3==5.24.0 |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
cromewar
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i uninstalled web3 and installed web3==5.24.0
its solved now. I couldnt find a how to delete this question but if there is anyone who has this issue maybe this will help
bye .D