2022. 4. 1. 14:45ㆍ개발 잡부/블록체인
개요
OpenZeppelin을 사용하다보면 (예를 들면 Ownable)
msg.sender대신 _msgSender()를 사용하는 경우가 있다.
import "./Context.sol";
...
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
Context.sol
GitHub - OpenZeppelin/openzeppelin-contracts: OpenZeppelin Contracts is a library for secure smart contract development.
OpenZeppelin Contracts is a library for secure smart contract development. - GitHub - OpenZeppelin/openzeppelin-contracts: OpenZeppelin Contracts is a library for secure smart contract development.
github.com
이 코드에서는 msg.sender를 _msgSender로, msg.data를 _msgData로 사용할 수 있게 한다.
주석을 보면 그 이유를 알 수 있는데,
Provides information about the current execution context, including the sender of the transaction and its data.
While these are generally available via msg.sender and msg.data, they should not be accessed in such a direct manner, since when dealing with meta-transactions the account sending and paying for execution may not be the actual sender (as far as an application is concerned).
This contract is only required for intermediate, library-like contracts.
meta-transaction을 처리 할 때 결제하는 계좌가 실제 보낸 계좌가 아닐 수 있다고 한다.
Sending gasless transactions - OpenZeppelin Docs
All Ethereum transactions use gas, and the sender of each transaction must have enough Ether to pay for the gas spent. Even though these gas costs are low for basic transactions (a couple of cents), getting Ether is no easy task: dApp users often need to g
docs.openzeppelin.com
메타 트랜젝션이란 제 3자를 끼고 하는 거래를 뜻한다고 한다...
나중에 좀 더 정확히 파악해 봐야겠다
'개발 잡부 > 블록체인' 카테고리의 다른 글
크립토 좀비 2-1. Testing Smart Contracts with Truffle (0) | 2022.04.01 |
---|---|
나만의 후원사이트 만들기 (cheers-coffee) 1 (0) | 2022.04.01 |
address에서 send, transfer를 호출할 수 없는 이슈 (0) | 2022.04.01 |
SPDX-License-Identifier 이슈 (0) | 2022.04.01 |
크립토 좀비 1-6. 앱 프론트엔드 & Web3.js (0) | 2022.03.31 |