[英]Solidity basics: what "msg.sender" stands for
I just started to learn Solidity as a personal challenge.我刚开始学习 Solidity 作为个人挑战。 I'm not a developer so I've a loooooong way to go.
我不是开发人员,所以我对 go 有很长的路要走。
I'm following the Ethereum.org tutorial, here is what I've got doubt about: What does [msg.sender]
stand for?我正在关注 Ethereum.org 教程,这是我有疑问的:
[msg.sender]
代表什么? I guess it is the wallet address of who triggered the contract, but I'm not sure.我猜是触发合约的钱包地址,但我不确定。
msg.sender
(address
): sender of the message (current call)msg.sender
(address
): 消息的发送者(当前通话)
msg.sender
will be the person who's currently connecting with the contract. msg.sender
将是当前与合约连接的人。
Later on, you'll probably deal with contracts connecting with contracts.稍后,您可能会处理与合同相关的合同。 In that case, the contract that is creating the call would be the
msg.sender
.在这种情况下,创建调用的合约将是
msg.sender
。
Check out the documentation here: https://docs.soliditylang.org/en/develop/units-and-global-variables.html#block-and-transaction-properties在此处查看文档: https ://docs.soliditylang.org/en/develop/units-and-global-variables.html#block-and-transaction-properties
Let's make it very simple.让我们让它变得非常简单。
There are two types of accounts in the Ethereum Chain
1). Externally Owned Accounts(EOA) [Person]
2). Contracts Accounts [Contracts on Chain]
Both accounts have their addresses.两个帐户都有自己的地址。
Wallet address of personA (EOA) is 0x0cE446987406E92DF41614C46F1d6df9Cc925847
. personA (EOA)的钱包地址是
0x0cE446987406E92DF41614C46F1d6df9Cc925847
。
Contract Address of Math.sol
is 0x0cE446987406E92DF41614C46F1d6df9Cc753869
and Math.sol
contains ContractA
0x0cE446987406E92DF41614C46F1d6df9Cc753869
Math.sol
Math.sol
包含ContractA
Contract Address of Addition.sol
is 0x0cE446987406E92DF41614C46F1d6df9Cc357241
and Addition.sol
contains ContractB
Addition.sol
的合约地址是0x0cE446987406E92DF41614C46F1d6df9Cc357241
并且Addition.sol
包含ContractB
Here, one of the functions of ContractB
is called from ContractA
.在这里,从
ContractB
调用ContractA
的功能之一。
So, whenever personA
calls any functions of 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
Here,这里,
msg.sender (address)
: means sender of the message (current call) msg.sender (address)
: 表示消息的发送者(当前通话)
on the other hand另一方面
address owner = msg.sender;
The msg.sender
is the address that has called or initiated a function or created a transaction. msg.sender
是调用或发起 function 或创建事务的地址。 Now, this address could be of a contract or even a person like you and me.现在,这个地址可能是合同的,甚至可能是你我这样的人。
That's why you may use msg.sender
instead of msg.sender()
这就是为什么你可以使用
msg.sender
而不是msg.sender()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.