[英]Why msg.sender has the address of the deployer (address isnt the caller)
[英]Why do I need to use `msg.sender` in my function if I pass an address as an argument?
學習堅固性。 到目前為止喜歡它,但想了解為什么以下塊不起作用。
contract Whatever {
mapping (address => uint) public ledger;
function withdrawAllMoney(address payable _to) public {
require(ledger[_to] > 0, "You do not have permission to withdrawl funds. Deposit first");
uint sent = ledger[_to]; // <----- error here - telling me to use msg.sender
ledger[_to] = 0;
_to.transfer(address(this).balance);
}
}
我很好奇為什么我不能在我傳遞給 function: ledger[_to]
的地址處索引到我的映射,因為 require 塊似乎有效。 在沒有msg.sender
的情況下無法傳輸是否存在安全原因?
我認為那是因為您想提取所有余額
address(this).balance
從技術上講,只有合約的所有者才能調用它。 根據您的代碼,任何人都可以提取所有余額。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.