[英]Why do I need to use `msg.sender` in my function if I pass an address as an argument?
Learning Solidity.学习坚固性。 Love it so far but would like to understand why the following block doesnt work.
到目前为止喜欢它,但想了解为什么以下块不起作用。
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);
}
}
I'm curious as to why I cant index into my mapping at the addres I'm passing into the function: ledger[_to]
as the require block seems to work.我很好奇为什么我不能在我传递给 function:
ledger[_to]
的地址处索引到我的映射,因为 require 块似乎有效。 Is there a security reason behind not being able to transfer without msg.sender
?在没有
msg.sender
的情况下无法传输是否存在安全原因?
I think that because you want to withdraw all the balance我认为那是因为您想提取所有余额
address(this).balance
Technically only the owner of the contract should be able to call this.从技术上讲,只有合约的所有者才能调用它。 Based on your code anyone can withdraw all the balance.
根据您的代码,任何人都可以提取所有余额。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.