Reputation: 23
pragma solidity >=0.6.0 <0.9.0;
//import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; ao importar este contracto o debaixo nao seria necessario mas usamos para ter um melhor entendimento do contrato
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
// getRoundData and latestRoundData should both raise "No data present"
// if they do not have data to report, instead of returning unset values
// which could be misinterpreted as actual reported values.
function getRoundData(uint80 _roundId)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}
contract FundMe {
//track de todos os endereços que interagiram com o contracto
mapping(address => uint256) public addressToAmmountFunded;
address public owner;
//tudo o que é feito nos constructor() é automaticamente aplicado na criaçao do smart contract
constructor() {
//como o primeiro msg.sender é o criador do smart contract fica automaticamente como owner
owner = msg.sender;
}
function fund() public payable {
uint256 minimunUSD = 500 * 10 ** 18; //define que minimunUSD tem de ser 50 mas é preciso multiplicar por 10^18 por estarmos a usar WEI
require(getConversionRate(msg.value) >= minimunUSD, "You need to invest more than 500USD in xxx tokens!"); // Se valor enviado nao for suficiente o ele reverte a transacçao
addressToAmmountFunded[msg.sender] += msg.value;
//contrato que so aceita ETH por isso é necessario fazer uma conversao para um USD conversion rate
}
function getVersion() public view returns (uint256){
AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e); // contrato definido encontrado em https://docs.chain.link/docs/ethereum-addresses/ que é ETH/USD
return priceFeed.version();
}
function getPrice() public view returns(uint256){
AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);
(,int256 answer,,,) = priceFeed.latestRoundData(); // O numero de virgulas representam as variaves em latest round data que nao estao a ser usadas
return uint256(answer * 10000000000);
}
function getLatestUpdate() public view returns(uint256){
AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);
(,,,uint256 updatedAt,) = priceFeed.latestRoundData(); // O numero de virgulas representam as variaves em latest round data que nao estao a ser usadas
return updatedAt;
}
// 1000000000
function getConversionRate(uint256 ethAmount) public view returns(uint256){
uint256 ethPrice = getPrice();
uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1000000000000000000 ; //divisao por 10^18 casas decimais do ethereum
return ethAmountInUsd;
}
//este modificador faz com que o codigo de withdraw() só corra depois de executar o require
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function withdraw() payable onlyOwner public {
msg.sender.transfer(address(this).balance);
}
}
In the last function withdraw() im getting the error TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address".
I'm using compiler version 0.8.7 of REMIX IDE
I've double-checked all the smart contracts and I can't see any way to solve it.
What I'm trying to do with this function is check all the value deposited on the smart contract and withdraw it to the owner address being the one who deployed the smart contract
Upvotes: 1
Views: 592
Reputation: 49709
Since you have modified it with onlyOwner, only the owner can call it. So
msg.sender
is actually owner
.
the owner should be payable. If there is no other bug in your code, this should solve it:
address payable owner;
Upvotes: 1