【问题标题】:INFO: Could not find files for the given pattern(s) - VSC and python信息:找不到给定模式的文件 - VSC 和 python
【发布时间】:2021-11-09 10:28:23
【问题描述】:

我一直在学习 Python 和智能合约的教程(我对编码完全陌生),并且在遵循每一步的同时,VSCode 不断返回以下消息 >INFO:找不到文件给定的模式。 尽管它仍然返回我要求它执行的任何操作:

from solcx import compile_standard, install_solc
import json
from web3 import Web3
import os
from dotenv import load_dotenv

load_dotenv()

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"]}
            }
        },
    },
    solc_version="0.6.0",
)
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"]

w3 = Web3(Web3.HTTPProvider("HTTP://127.0.0.1:7545"))
chain_id = 1337
my_address = "0x237d38135A752544a4980438c3dd9dFDe409Fb49"
private_key = os.getenv("PRIVATE_KEY")

# create the contract in python
SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)

# get the latest transaction
nonce = w3.eth.getTransactionCount(my_address)

# 1. build a transation
# 2. Sign a transation
# 3. Send a transation
transaction = SimpleStorage.constructor().buildTransaction(
    {"chainId": chain_id, "from": my_address, "nonce": nonce})

signed_txn = w3.eth.account.sign_transaction(
    transaction, private_key=private_key)

private_key = os.getenv("PRIVATE_KEY")
# Send the signed transaction
print("Deploying contract...")
tx_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print("Deployed!")
# working with the contract
# contract address
# Contract ABI

simple_storage = w3.eth.contract(address=tx_receipt.contractAddress, abi=abi)
# Call > simulate making the call and getting the return value, doesn't make a change on the blockchain
# Transact  > actually makes a state change

# Initial value of favorite number
print(simple_storage.functions.retrieve().call())
print("Updating contract...")

store_transaction = simple_storage.functions.store(15).buildTransaction(
    {"chainId": chain_id, "from": my_address, "nonce": nonce + 1}
)
signed_store_txn = w3.eth.account.sign_transaction(
    store_transaction, private_key=private_key)
send_store_tx = w3.eth.send_raw_transaction(signed_store_txn.rawTransaction)
tx_receipt = w3.eth.wait_for_transaction_receipt(send_store_tx)
print("Updated!")
print(simple_storage.functions.retrieve().call())

终端中的结果是:

PS C:\Users\chret\Documents\demo\web3_py_simple_storage> python deploy.py
INFO: Could not find files for the given pattern(s).
Deploying contract...
Deployed!
0
Updating contract...
Updated!
15

所以,我很困惑,我应该忽略警告“找不到给定模式的文件”吗?或者我可以做些什么来修复它/当我继续在这些文件中编码时它会产生问题吗?我尝试重新定位文件夹,包括环境变量/PATH 中的路径,但它不会阻止此消息显示。 它从一开始就一直在这样做,但我正在关注的视频中没有任何地方显示(youtube 上关于区块链的 freecodecamp 16h 视频教程)。

谢谢!

【问题讨论】:

    标签: python visual-studio-code ethereum


    【解决方案1】:

    我也有这个问题。 我无法在我的 Windows 环境中修复它。但是,

    github 链接到在 Windows 上的 Ubuntu 环境中设置 brownie 堆栈的教程,这对我来说完美无缺。而且很容易设置。

    https://medium.com/@cromewar/how-to-setup-windows-10-11-for-smart-contract-development-and-brownie-e7d8d13555b3

    文中未提及,但目前(26/11/2021),由于兼容性问题,您将需要安装 Node v16 和 ganache v7.0.0-alpha.2。

    请参阅 NVM 和节点版本的链接。 https://docs.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-wsl

    【讨论】:

    • 谢谢 Jared,我正在通过 tryhackme.com 学习网络安全,并且正在考虑在我的计算机上设置 Linux 操作系统,现在你成功说服我这样做了 :)跨度>
    猜你喜欢
    • 2021-09-25
    • 2021-10-24
    • 2020-07-13
    • 2010-10-13
    • 2019-01-29
    • 2017-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多