繁体   English   中英

Solidity 基础知识:“msg.sender”代表什么

[英]Solidity basics: what "msg.sender" stands for

我刚开始学习 Solidity 作为个人挑战。 我不是开发人员,所以我对 go 有很长的路要走。

我正在关注 Ethereum.org 教程,这是我有疑问的: [msg.sender]代表什么? 我猜是触发合约的钱包地址,但我不确定。

msg.sender ( address ): 消息的发送者(当前通话)

msg.sender将是当前与合约连接的人。

稍后,您可能会处理与合同相关的合同。 在这种情况下,创建调用的合约将是msg.sender

在此处查看文档: https ://docs.soliditylang.org/en/develop/units-and-global-variables.html#block-and-transaction-properties

让我们让它变得非常简单。

There are two types of accounts in the Ethereum Chain
1). Externally Owned Accounts(EOA) [Person]
2). Contracts Accounts [Contracts on Chain]

两个帐户都有自己的地址。

  • 现在,看一个例子。

personA (EOA)的钱包地址是0x0cE446987406E92DF41614C46F1d6df9Cc925847

0x0cE446987406E92DF41614C46F1d6df9Cc753869 Math.sol Math.sol包含ContractA

Addition.sol的合约地址是0x0cE446987406E92DF41614C46F1d6df9Cc357241并且Addition.sol包含ContractB

在这里,从ContractB调用ContractA的功能之一。

因此,每当personA调用ContractA的任何函数时。

In this scenario, if you print or get `msg.sender` and `tx.origin` inside function of `ContractB` then the result would be like this

msg.sender = `0x0cE446987406E92DF41614C46F1d6df9Cc753869` // You will get address of `ContractA`
tx.origin  = `0x0cE446987406E92DF41614C46F1d6df9Cc925847` // personA's (EOA) Wallet Address

这里,

msg.sender (address) : 表示消息的发送者(当前通话)

另一方面

address owner = msg.sender;

msg.sender是调用或发起 function 或创建事务的地址。 现在,这个地址可能是合同的,甚至可能是你我这样的人。

这就是为什么你可以使用msg.sender而不是msg.sender()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM