smartcontractkit / full-blockchain-solidity-course-py

Ultimate Solidity, Blockchain, and Smart Contract - Beginner to Expert Full Course | Python Edition
MIT License
10.67k stars 2.89k forks source link

Lesson 13 FULL STACK DEFI- FileNotFoundError: [Errno 2] No such file or directory: 'ganache-cli' #1824

Closed ellyblueeyes closed 1 year ago

ellyblueeyes commented 1 year ago

I did the script to to send brownie-config.yaml to front_end and when I run in the terminal deploy.py I get this error: 11

I don't know if it's something bad in the code or with the programs that I have installed, because I get the same error when I try to run codes in the previous projects as well. Thank you for the help!

1.Deploy.py

from scripts.helpful_scripts import get_account, get_contract from brownie import DappToken, TokenFarm, network, config from web3 import Web3 import yaml import json import os import shutil

KEPT_BALANCE = Web3.toWei(100, "ether")

def deploy_token_farm_and_dapp_token(front_end_update=False): account = get_account() dapp_token = DappToken.deploy({"from": account}) token_farm = TokenFarm.deploy( dapp_token.address, {"from": account}, publish_source=config["networks"][network.show_active()]["verify"], ) tx = dapp_token.transfer( token_farm.address, dapp_token.totalSupply() - KEPT_BALANCE, {"from": account} ) tx.wait(1)

dapp_token, weth_token, fau_token/dai

weth_token = get_contract("weth_token")
fau_token = get_contract("fau_token")
dict_of_allowed_tokens = {
    dapp_token: get_contract("dai_usd_price_feed"),
    fau_token: get_contract("dai_usd_price_feed"),
    weth_token: get_contract("eth_usd_price_feed"),
}
add_allowed_tokens(token_farm, dict_of_allowed_tokens, account)
if front_end_update:
    update_front_end()
return token_farm, dapp_token

def add_allowed_tokens(token_farm, dict_of_allowed_tokens, account): for token in dict_of_allowed_tokens: add_tx = token_farm.addAllowedTokens(token.address, {"from": account}) add_tx.wait(1) set_tx = token_farm.setPriceFeedContract( token.address, dict_of_allowed_tokens[token], {"from": account} ) set_tx.wait(1) return token_farm

def update_front_end():

Send the build folder

#copy_folders_to_front_end("./build", "./front_end/src/chain-info")

# Sending the front end our config in JSON format
with open("brownie-config.yaml", "r") as brownie_config:
    config_dict = yaml.load(brownie_config, Loader=yaml.FullLoader)
    with open("./front_end/src/brownie-config.json", "w") as brownie_config_json:
        json.dump(config_dict, brownie_config_json)
print("Front end updated!")

def main(): deploy_token_farm_and_dapp_token(front_end_update=True)

2.Update_front_end.py

from scripts.deploy import update_front_end

def main(): update_front_end()

  1. Helpful-scripts.py

from brownie import ( network, accounts, config, interface, LinkToken, MockV3Aggregator, MockWETH, MockDAI, Contract, )

INITIAL_PRICE_FEED_VALUE = 2000000000000000000000 DECIMALS = 18

NON_FORKED_LOCAL_BLOCKCHAIN_ENVIRONMENTS = ["hardhat", "development", "ganache"] LOCAL_BLOCKCHAIN_ENVIRONMENTS = NON_FORKED_LOCAL_BLOCKCHAIN_ENVIRONMENTS + [ "mainnet-fork", "binance-fork", "matic-fork", ]

contract_to_mock = { "eth_usd_price_feed": MockV3Aggregator, "dai_usd_price_feed": MockV3Aggregator, "fau_token": MockDAI, "weth_token": MockWETH, }

def get_account(index=None, id=None): if index: return accounts[index] if network.show_active() in LOCAL_BLOCKCHAIN_ENVIRONMENTS: return accounts[0] if id: return accounts.load(id) return accounts.add(config["wallets"]["from_key"])

def get_contract(contract_name):

contract_type = contract_to_mock[contract_name]
if network.show_active() in NON_FORKED_LOCAL_BLOCKCHAIN_ENVIRONMENTS:
    if len(contract_type) <= 0:
        deploy_mocks()
    contract = contract_type[-1]
else:
    try:
        contract_address = config["networks"][network.show_active()][contract_name]
        contract = Contract.from_abi(
            contract_type._name, contract_address, contract_type.abi
        )
    except KeyError:
        print(
            f"{network.show_active()} address not found, perhaps you should add it to the config or deploy mocks?"
        )
        print(
            f"brownie run scripts/deploy_mocks.py --network {network.show_active()}"
        )
return contract

def deploy_mocks(decimals=DECIMALS, initial_value=INITIAL_PRICE_FEED_VALUE):

print(f"The active network is {network.show_active()}")
print("Deploying Mocks...")
account = get_account()
print("Deploying Mock Link Token...")
link_token = LinkToken.deploy({"from": account})
print("Deploying Mock Price Feed...")
mock_price_feed = MockV3Aggregator.deploy(
    decimals, initial_value, {"from": account}
)
print(f"Deployed to {mock_price_feed.address}")
print("Deploying Mock DAI...")
dai_token = MockDAI.deploy({"from": account})
print(f"Deployed to {dai_token.address}")
print("Deploying Mock WETH")
weth_token = MockWETH.deploy({"from": account})
print(f"Deployed to {weth_token.address}")
ellyblueeyes commented 1 year ago

I installed again ganache-cli with npm install -g ganache-cli.