Why openzeppelin_ The address returned by msgsender() is 0

Q & A of Denglian community 2022-04-05 03:52:41 阅读数:57

openzeppelin_ openzeppelin address returned msgsender
IERC20(token0).transfer(address(this),token0Amount);

After I call the above method ,openzeppelin Of _msgSender() The return is 0 Not the user address or contract address , Why is that ?

function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; console.log("msg.sender: ",msg.sender); console.log("from: ",fromBalance); console.log("to: ",to); console.log("fromBalance: ",fromBalance); console.log("amount: ",amount); require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; } _balances[to] += amount; emit Transfer(from, to, amount); _afterTokenTransfer(from, to, amount); }

I get it directly msg.sender, The address you can get the contract is , Why call _msgSender() The address is 0

function _msgSender() internal view virtual returns (address) { return msg.sender; }
console.log: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 10000000000000000000000 transfer token0: 1 true bushu======== msg.sender: 0x69c955af73a583c10a5b0f3218d3406f93c35338 from: 0 to: 0x69c955af73a583c10a5b0f3218d3406f93c35338 fromBalance: 0 amount: 1

openzeppelin No special treatment , Incomprehensible



Other answers 1:

Other answers 2:
版权声明:本文为[Q & A of Denglian community]所创,转载请带上原文链接,感谢。 https://netfreeman.com/2022/03/202203232030178426.html