我一直在免费代码营 16 小时课程 中学习 Solidity - 并遇到以下问题:
brownie 网络添加开发 mainnet-fork-dev cmd=ganache-cli 主机=http://127.0.0.1 叉=https://eth-mainnet.alchemyapi.io/v2/$MY_WEB3_ALCHEMY_PROJECT_ID 账户=10 助记词=brownie 端口=8545
brownie run scripts/deploy.py --network mainnet-fork-dev
from brownie import FundMe, MockV3Aggregator, network, config
from scripts.helpful_scripts import (
get_account,
deploy_mocks,
LOCAL_BLOCKCHAIN_ENVIRONMENTS
)
from web3 import Web3
def deploy_fund_me():
account = get_account()
# if we are on rinkbey so on - use associated address
# otherwise deploy moks
if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
price_feed_address = config["networks"][network.show_active()]["eth_usd_price_feed"]
else:
# Deploy fake get price function is the network is fake like Ganeche
deploy_mocks()
price_feed_address = MockV3Aggregator[-1].address
fund_me = FundMe.deploy(
price_feed_address,
{"from": account},
publish_source = config["networks"][network.show_active()].get("verify"),
)
print(f'\n\n')
print(f'Active network is {network.show_active()}')
print(f'Price_feed_address is {price_feed_address}')
print(f'From account is {account}')
print(f'Contract deployed to {fund_me.address}')
print(f'\n\n')
return fund_me
def main():
deploy_fund_me()
运行 scripts/deploy.py::main... 交易已发送:
0x439c0b1aa486c393d04b5b5b329da17d344b9cad751e25ff222b7e18be383021
Gas price: 0.0 gwei Gas limit: 6721975 Nonce: 0
FundMe.constructor confirmed Block: 1 Gas used: 405741 (6.04%)
FundMe deployed at: 0x9abEBCe93172DDBA444312C93d0c88372EbA5B31
但是当我尝试调用
FundMe[-1]
时,合约并未部署 - 数组为空。
在部署文件夹中,我没有看到我的 mainnet-fork-dev 的 ChainId
在 Ganache 中我看到了这笔交易,但它似乎没有签名......(我不确定,我在区块链方面是超级新人)
我该如何解决这个问题?
get_account()和deploy_mocks():
from brownie import network, config, accounts, MockV3Aggregator
from web3 import Web3
FORKED_LOCAL_ENVIRONMENTS = ["mainnet-fork", "mainnet-fork-dev"]
LOCAL_BLOCKCHAIN_ENVIRONMENTS = ["development", "ganache-local"]
DECIMALS = 8
STARTING_PRICE = 200000000000
def get_account():
if (
network.show_active() in LOCAL_BLOCKCHAIN_ENVIRONMENTS
or network.show_active() in FORKED_LOCAL_ENVIRONMENTS
):
return accounts[0]
else:
return accounts.add(config["wallets"]["from_key"])
def deploy_mocks():
print(f"The active network is {network.show_active()}")
print("Deploying Mocks...")
if len(MockV3Aggregator) <= 0:
MockV3Aggregator.deploy(DECIMALS, STARTING_PRICE, {"from": get_account()})
print("Mocks Deployed!")
我遇到了完全相同的问题,我通过这样做解决了这个问题
"gas_price": "60 gwei" 当部署你的合约时,你的代码显示如下:
from brownie import FundMe, MockV3Aggregator, network, config
from scripts.helpful_scripts import (
get_account,
deploy_mocks,
LOCAL_BLOCKCHAIN_ENVIRONMENTS
)
from web3 import Web3
def deploy_fund_me():
account = get_account()
# if we are on rinkbey so on - use associated address
# otherwise deploy moks
if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
price_feed_address = config["networks"][network.show_active()]["eth_usd_price_feed"]
else:
# Deploy fake get price function is the network is fake like Ganeche
deploy_mocks()
price_feed_address = MockV3Aggregator[-1].address
fund_me = FundMe.deploy(
price_feed_address,
{"from": account,
"gas_price": "60 gwei"
},
publish_source = config["networks"][network.show_active()].get("verify"),
)
print(f'\n\n')
print(f'Active network is {network.show_active()}')
print(f'Price_feed_address is {price_feed_address}')
print(f'From account is {account}')
print(f'Contract deployed to {fund_me.address}')
print(f'\n\n')