Joshua Witt
Joshua Witt

Reputation: 1

FundMe contract doesn't deploy in my mainnet-fork-dev network in Brownie + Alchemy

I've been learning Solidity on the Free Code Camp 16 hour course - and stuck with the following problem:

  1. I created fork of Ethereum Mainnet in Brownie using Alchemy:

brownie networks add development mainnet-fork-dev cmd=ganache-cli host=http://127.0.0.1 fork=https://eth-mainnet.alchemyapi.io/v2/$MY_WEB3_ALCHEMY_PROJECT_ID accounts=10 mnemonic=brownie port=8545

  1. Run deploy.py:
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()
  1. Terminal gives me:

Running scripts/deploy.py::main... Transaction sent:

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

But the contract doesn’t deploy, when I try to call FundMe[-1] - the array is empty.

And in the deployments folder, I don’t see ChainId of my mainnet-fork-dev

In Ganache I see this transaction, but it seems like it's not signed ... (I'm not sure, I'm super new in Blockchain)

enter image description here

How can I fix that?

get_account() and 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!")

Upvotes: 0

Views: 614

Answers (1)

Kamuran
Kamuran

Reputation: 1

I had the exact same issue and I solved this issue by adding "gas_price": "60 gwei" when deploying your contract, so your code show like this:

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')

You can also add these:

from brownie.network import gas_price
from brownie.network.gas.strategies import LinearScalingStrategy

gas_strategy = LinearScalingStrategy("60 gwei", "70 gwei", 1.1)

gas_price(gas_strategy)

and in your smart contract do this:

fund_me = FundMe.deploy(
        price_feed_address,
        {"from": account,
        "gas_price": gas_price#// here i add gas_price
    }, 
        publish_source = config["networks"][network.show_active()].get("verify"),
    )

Upvotes: 0

Related Questions