'INFO: Could not find files for the given pattern(s). Codecamp Solidity Course
I'm working on the free Solidity codecamp course. Around 3:58:44, we are trying to print a nonce. My error returns as "INFO: Could not find files for the given pattern(s). And then it says Traceback (most recent call last) etc, and throws a bunch of bytecode.
It should just return "0"
I'm completely new to coding, any help or directions would be appreciated.
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()
# Compile Our Solidity
install_solc("0.6.0"),
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)
# To deploy a contract, you need the bytecode and the ABI
# get bytecode
bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["evm"]
["bytecode"]
["object"]
# get abi
abi = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["abi"]
# for connecting to ganache
w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:7545"))
chaind_id = 5777
my_address = "0x16B7A2A9c869Fd89BAC5cD60CAf967C67d70F835"
private_key = "0x2f89f545fa407e76dc129908bb48a6ae457f88828c2f0a69b3737320a50b99f6"
# Create the contract in python
SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)
# Get the latest transaction
nonce = w3.eth.getTransactionCount(my_address)
print(nonce)
Solution 1:[1]
- Make sure
SimpleStorage.solis in same directory asdeploy.py.
Also I noticed that chainId is wrong. it should be 1337. 5777 is the network id for ganache.
chain_id=1337
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
