Replies: 8 comments 20 replies
-
from brownie import FundMe
from scripts.helpful_scripts import get_account
def fund():
fund_me = FundMe[-1]
account = get_account()
entrance_fee = fund_me.getEntranceFee()
print(entrance_fee)
def main():
fund() |
Beta Was this translation helpful? Give feedback.
-
from brownie import network, config, accounts, MockV3Aggregator
from web3 import Web3
DECIMALS = 8
STARTING_PRICE = 200000000000
LOCAL_BLOCKCHAIN_ENVIRONMENTS = ["development", "ganache-local3"]
def get_account():
if network.show_active() in LOCAL_BLOCKCHAIN_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!") |
Beta Was this translation helpful? Give feedback.
-
from brownie import network, config, FundMe, MockV3Aggregator
from scripts.helpful_scripts import get_account, deploy_mocks, MockV3Aggregator, LOCAL_BLOCKCHAIN_ENVIRONMENTS
def deploy_fund_me():
account = get_account()
if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
price_feed_address = config["networks"][network.show_active()][
"eth_usd_price_feed"
]
else:
deploy_mocks()
price_feed_address = MockV3Aggregator[-1].address
fund_me = FundMe.deploy(
{"from": account},
publish_source=config["networks"][network.show_active()].get("verify"),
)
print(f"Contract deploy to {fund_me.address}")
def main():
deploy_fund_me() |
Beta Was this translation helpful? Give feedback.
-
// SPDX-License-Identifier: MIT
// Smart contract that lets anyone deposit ETH into the contract
// Only the owner of the contract can withdraw the ETH
pragma solidity >=0.6.6 <0.9.0;
// Get the latest ETH/USD price from chainlink price feed
import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol";
contract FundMe {
// safe math library check uint256 for integer overflows
using SafeMathChainlink for uint256;
//mapping to store which address depositeded how much ETH
mapping(address => uint256) public addressToAmountFunded;
// array of addresses who deposited
address[] public funders;
//address of the owner (who deployed the contract)
address public owner;
// the first person to deploy the contract is
// the owner
constructor() public {
owner = msg.sender;
}
function fund() public payable {
// 18 digit number to be compared with donated amount
uint256 minimumUSD = 50 * 10**18;
//is the donated amount less than 50USD?
require(
getConversionRate(msg.value) >= minimumUSD,
"You need to spend more ETH!"
);
//if not, add to mapping and funders array
addressToAmountFunded[msg.sender] += msg.value;
funders.push(msg.sender);
}
//function to get the version of the chainlink pricefeed
function getVersion() public view returns (uint256) {
AggregatorV3Interface priceFeed = AggregatorV3Interface(
0x9326BFA02ADD2366b30bacB125260Af641031331
);
return priceFeed.version();
}
function getPrice() public view returns (uint256) {
AggregatorV3Interface priceFeed = AggregatorV3Interface(
0x9326BFA02ADD2366b30bacB125260Af641031331
);
(, int256 answer, , , ) = priceFeed.latestRoundData();
// ETH/USD rate in 18 digit
return uint256(answer * 10000000000);
}
// 1000000000
function getConversionRate(uint256 ethAmount)
public
view
returns (uint256)
{
uint256 ethPrice = getPrice();
uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1000000000000000000;
// the actual ETH/USD conversation rate, after adjusting the extra 0s.
return ethAmountInUsd;
}
function getEntranceFee() public view returns (uint256) {
uint256 minimumUSD = 50 * 10**18;
uint256 price = getPrice();
uint256 precision = 1 * 10**18;
return (minimumUSD * precision) / price;
}
//modifier: https://medium.com/coinmonks/solidity-tutorial-all-about-modifiers-a86cf81c14cb
modifier onlyOwner() {
//is the message sender owner of the contract?
require(msg.sender == owner);
_;
}
// onlyOwner modifer will first check the condition inside it
// and
// if true, withdraw function will be executed
function withdraw() public payable onlyOwner {
msg.sender.transfer(address(this).balance);
//iterate through all the mappings and make them 0
//since all the deposited amount has been withdrawn
for (
uint256 funderIndex = 0;
funderIndex < funders.length;
funderIndex++
) {
address funder = funders[funderIndex];
addressToAmountFunded[funder] = 0;
}
//funders array will be initialized to 0
funders = new address[](0);
}
} |
Beta Was this translation helpful? Give feedback.
-
dotenv: .env
networks:
kovan:
eth_usd_price_feed: '0x9326BFA02ADD2366b30bacB125260Af641031331'
verify: True
development:
verify: False
ganache-local3:
verify: False
dependencies:
# - <organization/repo>@<version>
- smartcontractkit/chainlink-brownie-contracts@1.1.1
compiler:
solc:
remappings:
- '@chainlink=smartcontractkit/chainlink-brownie-contracts@1.1.1'
wallets:
from_key: ${PRIVATE_KEY} |
Beta Was this translation helpful? Give feedback.
-
|
i have tried to delete and remake the networks on ganache, double checked the .env and tried to restart vs code etc and nothing seems to work |
Beta Was this translation helpful? Give feedback.
-
|
Hello @this is pretty common when brownie is not able to find the previous deployments of the contract so instead this: def fund():
fund_me = FundMe[-1]
account = get_account()
entrance_fee = fund_me.getEntranceFee()
print(entrance_fee)
|
Beta Was this translation helpful? Give feedback.
-
|
Doing further research I strongly think the error is here: function getPrice() public view returns (uint256) {
AggregatorV3Interface priceFeed = AggregatorV3Interface(
0x9326BFA02ADD2366b30bacB125260Af641031331
);
(, int256 answer, , , ) = priceFeed.latestRoundData();
// ETH/USD rate in 18 digit
return uint256(answer * 10000000000);
}answer must be marked as int. not int256, you'll transform it later. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
hello, i am gettting this error when i attempt to deploy fund_and_withdraw.py
Beta Was this translation helpful? Give feedback.
All reactions