[英]Send and transfer are only available for objects of type address payable , not address
[英]Withdraw function send is only available for objects of type "address payable"
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);
}
}
在最后一個 functionwithdraw() 中,我收到錯誤 TypeError:“發送”和“轉移”僅適用於“應付地址”類型的對象,而不是“地址”類型的對象。
我正在使用 REMIX IDE 的編譯器版本 0.8.7
我已經仔細檢查了所有的智能合約,但我看不到任何解決方法。
我試圖用這個 function 做的是檢查存入智能合約的所有價值並將其提取到所有者地址,即部署智能合約的人
由於你用onlyOwner修改了它,所以只有所有者可以調用它。 所以msg.sender
實際上是owner
。 業主應付款。 如果您的代碼中沒有其他錯誤,這應該可以解決它:
address payable owner;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.