I run this code in brownie: brownie run scripts/deploy.py --networks Rinkeby
deploy.py:
from brownie import network, config, accounts
from brownie import FundMe
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 get_account():
if network.show_active() == "development":
return accounts[0]
else:
return accounts.add(config['wallets']['from_key'])
def main():
deploy_fund_me()
.............................................................................. FundMe.sol:
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.6 ;
import "smartcontractkit/chainlink-brownie-contracts@1.1.1/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "smartcontractkit/chainlink-brownie-contracts@1.1.1/contracts/src/v0.6/vendor/SafeMathChainlink.sol";
//.......................................................................................................
contract FundMe {
using SafeMathChainlink for uint256;
mapping(address => uint256) public addressToAmountFunded;
address[] public funders;
address public owner;
constructor() public {
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){
AggregatorV3Interface priceFeed = AggregatorV3Interface(0xa7e39728bFF3b2da35F90E95c108Fcf2cb021D72);
return priceFeed.version();
}
function getPrice() public view returns(uint256){
AggregatorV3Interface priceFeed = AggregatorV3Interface(0xa7e39728bFF3b2da35F90E95c108Fcf2cb021D72);
(,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;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function withdraw() payable onlyOwner public {
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);
}
}
//..............................................................................................
......................