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:
- 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;
}
}
- 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"])
- 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")