Linked Questions

69
votes
2answers
24k views

What's the difference between 'msg.sender' and 'tx.origin'?

If either are used in the body of a Solidity function that may change the state of a contract (write call), what's the primary difference and/or benefit of using one over the other. For example: ...
14
votes
5answers
8k views

How to make someone else pay for Gas?

My understanding is that msg.sender pays the gas fee. Can a smart contract be written in such a way that it's always the contract owner who pay the fees? As an example, in an ERC20 token when someone ...
9
votes
2answers
1k views

Is it possible to call another contract from a contract maintaining the msg.sender of the original caller?

Imagine that Alice calls a contract method C1 and that method calls another method in contract C2. Regularly msg.sender equals the Alice Account in the C1 method. And msg.sender equals the C1 ...
0
votes
1answer
2k views

DeclarationError: Undeclared identifier. But already declared

DeclarationError: Undeclared identifier.on line 8,12,14.
0
votes
1answer
768 views

deletegateCall to change contract's ownership

I am currently going deep into some Solidity functionalities and I would like to be able to change a contract's A ownership from a contract B, knowing that the caller of contract B is the owner of ...
0
votes
2answers
351 views

Why aren't block hashes a reliable source of randomness?

I just saw this answer that informed me that block hashes were not a reliable source of randomness. In what situation are block hashes not a reliable way to obtain randomness?
0
votes
1answer
261 views

How to avoid using tx.origin when we really need it?

It's been recommended that we should avoid using tx.origin. However, there're some cases it's really needed, like the following case. Assume we have two smart contracts: Sc1 and Sc2, both of which ...
0
votes
1answer
260 views

Trouble using delegatecall to pass msg.sender to another contract

I'm trying to mint an NFT token in contract B by calling a method on contract A, but I want msg.sender (in contract B) to be the address that calls the function on A, not contract A's address. I ...
5
votes
1answer
116 views

What happens to immutable contracts when Ethereum 2.0 will likely change the 15s block time?

Immutable contracts that need to have a time system for handling their functions process are mostly based on block.number system. They assume there is about 15seconds between each block and thus ...
1
vote
0answers
47 views

msg.sender and tx.origin - how to use them in practice? [duplicate]

I wrote a contract A that uses msg.sender for authentication: When A creates an item it stores msg.sender in itemsOwners mapping (itemOwners[itemId] = msg.sender;). Later A compares msg.sender to ...
0
votes
1answer
34 views

Revert Assert best option

I have a contract(A) function with the standard onlyOwner access. If I call directly from the deployed account the function works fine. But when I import this contract(A) into another contract(B) and ...