0

Hello there I'm currently following this tutorial https://www.youtube.com/watch?v=M576WGiDBdQ by Patrick Collins. I have a problem when I try to deploy the script:

(base) elly@elly-Lenovo-G50-80:~/smartcontract_lottery$ brownie run scripts/deploy.py
Brownie v1.19.0 - Python development framework for Ethereum
SmartcontractLotteryProject is the active project.
  File "brownie/_cli/__main__.py", line 64, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "brownie/_cli/run.py", line 45, in main
    network.connect(CONFIG.argv["network"])
  File "brownie/network/main.py", line 31, in connect
    active = CONFIG.set_active_network(network)
  File "brownie/_config.py", line 74, in set_active_network
    id_ = self.settings["networks"]["default"]
TypeError: string indices must be integers

I will include all the files:

  1. Lottery.sol
// SPDX-License-Identifier:MIT
pragma solidity ^0.6.6;

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@chainlink/contracts/src/v0.6/VRFConsumerBase.sol";

contract Lottery is VRFConsumerBase, Ownable {
    address payable[] public players;
    address payable public recentWinner;
    uint256 public randomness;
    uint256 public usdEntryFee;
    AggregatorV3Interface internal ethUsdPriceFeed;

    enum LOTTERY_STATE {
        OPEN,
        CLOSED,
        CALCULATING_WINNER
    }

    LOTTERY_STATE public lottery_state;
    uint256 public fee;
    bytes32 public keyhash;

    constructor(
        address _priceFeedAddress,
        address _vrfCoordinator,
        address _link,
        uint256 _fee,
        bytes32 _keyhash
    ) public VRFConsumerBase(_vrfCoordinator, _link) {
        usdEntryFee = 50 * (10**18);
        ethUsdPriceFeed = AggregatorV3Interface(_priceFeedAddress);
        lottery_state = LOTTERY_STATE.CLOSED;
        fee = _fee;
        keyhash = _keyhash;
    }

    function enter() public payable {
        require(lottery_state == LOTTERY_STATE.OPEN);
        require(msg.value >= getEntranceFee(), "Not enough ETH!");
        players.push(msg.sender);
    }

    function getEntranceFee() public view returns (uint256) {
        (, int256 price, , , ) = ethUsdPriceFeed.latestRoundData();
        uint256 adjustedPrice = uint256(price) * 10**10;
        uint256 costToEnter = (usdEntryFee * 10**18) / adjustedPrice;
        return costToEnter;
    }

    function startLottery() public {
        require(
            lottery_state == LOTTERY_STATE.CLOSED,
            "Can't start a new lottery yet!"
        );
        lottery_state == LOTTERY_STATE.OPEN;
    }

    function endLottery() public onlyOwner {
        lottery_state = LOTTERY_STATE.CALCULATING_WINNER;
        bytes32 requestId = requestRandomness(keyhash, fee);
    }

    function fulfillRandomness(bytes32 _requestId, uint256 _randomness)
        internal
        override
    {
        require(
            lottery_state == LOTTERY_STATE.CALCULATING_WINNER,
            "You are not there yet!"
        );
        require(_randomness > 0, "random-not-found");
        uint256 indexOfWinner = _randomness % players.length;
        recentWinner = players[indexOfWinner];
        recentWinner.transfer(address(this).balance);
        //Reset
        players = new address payable[](0);
        lottery_state = LOTTERY_STATE.CLOSED;
        randomness = _randomness;
    }
}
  1. Deploy_lottery.py
from scripts.helpful_scripts import get_account


def deploy_lottery():
    account= get_account()


def main():
    deploy_lottery()

3.Brownie-config.yaml

dependencies:
  - smartcontractkit/[email protected]
  - OpenZeppelin/[email protected]
compiler:
  solc:
    remappings:
      - '@chainlink=smartcontractkit/[email protected]' 
      - '@openzeppelin=OpenZeppelin/[email protected]'
networks: 'development'
mainnet-fork:
    eth_usd_price_feed: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419'      
wallets:
from_key: ${PRIVATE_KEY}    

4.Helpful_scripts.py

from brownie import accounts, network, config

FORKED_LOCAL_ENVIRONMENTS= ["mainnet-fork", "mainnet-fork-dev"]
LOCAL_BLOCKCHAIN_ENVIRONMENTS= ["development", "ganache-local"]


def get_account(index=None, id=None):
    if index:
        return accounts[index]
    if id:
        return accounts.load(id)
    if (
        network.show_active() in LOCAL_BLOCKCHAIN_ENVIRONMENTS
        or network.show_active() in FORKED_LOCAL_ENVIRONMENTS
    ):
        return accounts[0]
        
    return accounts.add(config["wallets"]["from_key"])
  1. Test_lottery.py
from brownie import Lottery, accounts, config, network
from web3 import Web3


def test_get_entrance_fee():
    account=accounts[0]
    lottery=Lottery.deploy(
        config["networks"][network.show_active()]["eth_usd_price_feed"],
         {"from": account},
         )
#assert lottery.getEntranceFee()> Web3.toWei(0.018, "ether")
#assert lottery.getEntranceFee()< Web3.toWei(0.02, "ether")

1 Answer 1

1

I don't know, but looks like your Brownie config is not correct, can you try this file please:

dependencies:
  - smartcontractkit/[email protected]
  - OpenZeppelin/[email protected]
compiler:
  solc:
    remappings:
      - '@chainlink=smartcontractkit/[email protected]' 
      - '@openzeppelin=OpenZeppelin/[email protected]'
networks:
      default: 'development'
mainnet-fork:
    eth_usd_price_feed: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419'      
wallets:
from_key: ${PRIVATE_KEY}

Specifically notice the networks key which now has a sub-key called default. Also, in the following example, the config file seems to need the default key under the networks key: https://eth-brownie.readthedocs.io/en/stable/config.html

There is more evidence in your error: It looks like the error happens right on this line id_ = self.settings["networks"]["default"], notice how it's trying to access the networks/default "path" in your config file.

But in the file you shared, that path does not exist.

14
  • Thank you, still doesn't work. I reinstalled Brownie, nothing.
    – Elena 46
    Commented Aug 26, 2022 at 14:54
  • Okay, well a shot in the dark. Are you getting the same error still? Still looks to me like the internal state of self.settings is wrong. It might not load the settings correctly. Can you try this: On the command line type python. Then: import brownie brownie.__path__ Then, find this file in that path: brownie/_config.py And print out self.settings right before line 74 in that file. Just to see the settings. Commented Aug 26, 2022 at 15:32
  • The error that I get: SmartcontractLotteryProject is the active project. File "brownie/_cli/__main__.py", line 64, in main importlib.import_module(f"brownie._cli.{cmd}").main() File "brownie/_cli/run.py", line 45, in main network.connect(CONFIG.argv["network"]) File "brownie/network/main.py", line 31, in connect active = CONFIG.set_active_network(network) File "brownie/_config.py", line 74, in set_active_network id_ = self.settings["networks"]["default"] TypeError: list indices must be integers or slices, not str
    – Elena 46
    Commented Aug 26, 2022 at 20:58
  • elly@elly-Lenovo-G50-80:~/smartcontract_lottery$ python Python 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import brownie >>> brownie.__path__ ['/home/elly/.local/lib/python3.8/site-packages/brownie'] >>> brownie/_config.py Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name '_config' is not defined >>> brownie/config.py Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'config' is not defined
    – Elena 46
    Commented Aug 26, 2022 at 21:01
  • It seems that there is no site-packages in Python and no brownie.
    – Elena 46
    Commented Aug 26, 2022 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.