[英]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.