full-blockchain-solidity-course-py
full-blockchain-solidity-course-py copied to clipboard
Lesson 6. Brownie FUNDME- ERROR cannot import name 'get_account' from 'scripts.helpful_scripts'
After following step by step the lesson I find an error that I cannot solve. I am putting here the entire code.
1.FUND ME // SPDX-License-Identifier: MIT
pragma solidity ^0.6.6;
import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol"; import "@chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol";
contract FundMe { using SafeMathChainlink for uint256;
mapping(address => uint256) public addressToAmountFunded;
address[] public funders;
address public owner;
AggregatorV3Interface public priceFeed;
// if you're following along with the freecodecamp video
// Please see https://github.com/PatrickAlphaC/fund_me
// to get the starting solidity contract code, it'll be slightly different than this!
constructor(address _priceFeed) public {
priceFeed = AggregatorV3Interface(_priceFeed);
owner = msg.sender;
}
function fund() public payable {
uint256 minimumUSD = 50 * 10**18;
require(
getConversionRate(msg.value) >= minimumUSD,
"You need to spend more ETH!"
);
addressToAmountFunded[msg.sender] += msg.value;
funders.push(msg.sender);
}
function getVersion() public view returns (uint256) {
return priceFeed.version();
}
function getPrice() public view returns (uint256) {
(, int256 answer, , , ) = priceFeed.latestRoundData();
return uint256(answer * 10000000000);
}
// 1000000000
function getConversionRate(uint256 ethAmount)
public
view
returns (uint256)
{
uint256 ethPrice = getPrice();
uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1000000000000000000;
return ethAmountInUsd;
}
function getEntranceFee() public view returns (uint256) {
// minimumUSD
uint256 minimumUSD = 50 * 10**18;
uint256 price = getPrice();
uint256 precision = 1 * 10**18;
// return (minimumUSD * precision) / price;
// We fixed a rounding error found in the video by adding one!
return ((minimumUSD * precision) / price) + 1;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function withdraw() public payable onlyOwner {
msg.sender.transfer(address(this).balance);
for (
uint256 funderIndex = 0;
funderIndex < funders.length;
funderIndex++
) {
address funder = funders[funderIndex];
addressToAmountFunded[funder] = 0;
}
funders = new address[](0);
}
} 2.BROWNIE-CONFIG.YAML dependencies:
- smartcontractkit/[email protected]
compiler:
solc:
remappings:
- '@chainlink=smartcontractkit/[email protected]' dotenv: .env wallets: from_key: ${PRIVATE_KEY}
- DEPLOY.PY from brownie import FundMe from scripts.helpful_scripts import get_account
def deploy_fund_me(): account=get_account() fund_me=FundMe.deploy({"from": account}, publish_source=True) print(f"Contract deployed to {fund_me.address}")
def main(): deploy_fund_me()
- .env export PRIVATE_KEY = "0x753aa243016b908fc6f7c21964201f11c1bf46cca2fe2ba2359cfeff9bbed00e" export WEB3_INFURA_PROJECT_ID = "0xbb18dd19aeda4a56a474a5e795e826de" export ETHERSCAN_TOKEN = DPGZQ3V1B593F8FX4X1YETVU7WKY8PG9BV
When I try to run it in terminal I get this error: Brownie v1.19.0 - Python development framework for Ethereum
BrownieFundMeProject is the active project.
File "brownie/_cli/run.py", line 55, in main
_include_frame=True,
File "brownie/project/scripts.py", line 60, in run
module = _import_from_path(script)
File "brownie/project/scripts.py", line 156, in _import_from_path
_import_cache[import_str] = importlib.import_module(import_str)
File "/home/elly/anaconda3/lib/python3.7/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen, line line, in in
File "<frozen, line line, in in
File "<frozen, line line, in in
File "<frozen, line line, in in
File "<frozen, line line, in in
File "<frozen, line line, in in
File "./scripts/deploy.py", line 2, in
You didn't upload the codes for your helpful-scripts. The get_account() function might be missing
The code for helpful_scripts.py
from brownie import network, config, accounts from scripts.helpful_scripts import get_account
def get_account(): if network.show_active()=="development": return accounts[0] else: return accounts.add(config["wallets"]["from_key"])
In your scripts.helpful_scripts. You cannot add this line in your input parameters
from scripts.helpful_scripts import get_account
Remove it and let's see if your code works this time.
I remove the line and I got the following error: constructor Sequence has incorrect length, expected 1 but got 0
I would prefer a screenshot of the error codes