Questions tagged [msg.sender]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
2 answers
20 views

msg.sender not recognized

I am getting the following error for the code // SPDX-License-Identifier: MIT pragma solidity ^0.8.7 ; contract Variables { //Global variables uint public pubInt = 25; bool public truth = ...
  • 191
0 votes
2 answers
15 views

What is standard practice to cast msg.sender to "payable"?

Introduction I am working on a bounty contract. Here is the function for somebody answering the bounty. I am trying to figure out when it is better to cast to payable, it seems intuitively that always ...
0 votes
0 answers
10 views

Why does signing a message include wallet address?

while creating a message why does it require to have a wallet address, if msg.sender can be used? I mean if in a case, Can we remove wallet address parameter in message while signing if msg.sender can ...
1 vote
0 answers
18 views

This is the source code for adding the token to the wallet, but the token is not added to the wallet [closed]

ERC20 Token smart contract: // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./ERC20.sol"; contract Shinobi is ERC20 { constructor (...
0 votes
1 answer
27 views

`msg.sender` instead of `tx.origin`

I am new to solidity but I have read at many times that tx.origin should be avoided & msg.sender should be used . There is a given demo on this in solidity page. It says like :- Never use tx....
  • 21
1 vote
2 answers
42 views

why msg.sender always gives me 0x0000000000000000000?

I want to call a contract method like this: pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/...
  • 182
0 votes
1 answer
23 views

How is transferring to payable(msg.sender) costing less gas than transferring to an address?

Consider the contract: // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; contract Test { address payable public owner; constructor() { owner = payable(msg.sender); } ...
0 votes
0 answers
41 views

OpenZeppelin Context.sol, when to use & why?

When, and why is it better to use functions _msgSender() & _msgData() introduced by the Context.sol by OpenZeppelin, instead of msg.sender & msg.data?
  • 81
0 votes
1 answer
22 views

transaction fail after calling transfer to the contract itself

I have this line in some function in an ERC721 contract: IERC20 instance = IERC20(token_address); instance.transfer(address(this),1); And when deploying the contract I make sure the caller of the ...
0 votes
0 answers
23 views

tx.origin:time of initialization (i.e. at deployment or at the start of transaction)? ,fixed or unfixed? , understanding the condition?

I got the following code from: EthereumBook 1. contract Phishable { 2. address public owner; 3. 4. constructor (address _owner) { 5. owner = _owner; 6. } 7. 8. ...
  • 1,285
0 votes
1 answer
24 views

Need to specify the amount with payable(msg.sender)?

I am working through Mastering Ethereum and have been building their first example Faucet Contract. I recognize that a lot of their syntax is out of date, and written in ^0.4.19. I've been writing it ...
  • 1
0 votes
1 answer
40 views

I accidentally sent my KINDER (BNB token) to the KINDER token contract address. Can I get them back? (I believe I have the source code too)

I was trying to send some of my KINDER tokens to another wallet I own and somehow I sent it to the KINDER token contract address. I have since reached out to an admin in the KINDER telegram group. He ...
0 votes
1 answer
34 views

How to send ether from smart contract to a particular address

I initially transferred some ether into the smart contract when deployed and in one of the function I should be transferring ether to the address of the msg.sender. Help me out if you can!
  • 1
0 votes
0 answers
94 views

What are the input parameters for keccak256?

I'm trying to interact with a smart contract in python. With Metamask i can see, that there is a signature trasferred to verify my wallet. Now the point is how to calculate this signature to use a ...
0 votes
2 answers
2k views

Error: Returned error: unknown account - Web3 be the msg.sender of a functioncall to a Contract

i trying to call the function getRewards() from this contract: https://polygonscan.com/address/0x4AB071C42C28c4858C4BAc171F06b13586b20F30#code This function use msg.sender to give me the rewards to my ...
0 votes
1 answer
253 views

how to use the value of msg.value and msg.sender of a contract, when a function calls a different contract

I'm studing Solidity and tring to understand how it works. Starting from Safe Remote Purchase in the "Solidity section by example" the doc (https://docs.soliditylang.org/en/v0.8.12/solidity-...
  • 3
0 votes
1 answer
98 views

When does msg.sender change?

If a function inside a contract calls another function in the same contract, is the msg.sender now the contract or still the original address that sent the initial transaction? I know if contract A ...
0 votes
1 answer
200 views

What kinds of functions are executed on-chain vs. off-chain?

I was building a withdrawal function for a contract that was using msg.sender.call{value: balance}, after checking that the given msg.sender was registered in the contract and had the given balance; ...
1 vote
2 answers
2k views

How to send ether from msg.sender to another address from within the contract

I'm new to solidity and I'm currently experimenting with smart contracts. As shown in the code below (only a part), I want to write a contract that lets you borrow money by paying a fee. I implemented ...
0 votes
1 answer
171 views

How to input a value into a function without parameter on Remix?

I read this where it has a function deposit() as below, without any parameter. We are supposed to send a value to msg.value but how do you do that in Remix as I can't find one text field for deposit ...
2 votes
0 answers
76 views

How to connect wallet / set caller for Read Contract buttons on Etherscan?

When I use the "Read Contract" tab on Etherscan, it works even if I didn't "connect" by Web3 wallet. It seems to be reading the blockchain passively. The thing is, one of the ...
0 votes
1 answer
95 views

How to create a "hasBalance" modifier in solidity for any token address?

I've been researching if it's possible to create a modifier that checks if msg.sender has any given amount of a token address. Use Case: limit certain functions to owners of a given token or NFT. I've ...
0 votes
1 answer
71 views

If a contract call fails at require is the ethereum value returned to msg sender?

According to this and this answer any remaining gas after a require statements assert condition fails is returned/refunded back to msg.sender but what about any ETHER sent in that transaction call i.e....
  • 340
0 votes
1 answer
161 views

Solidity 0.4, send ether through smart contract

I am struggling to find how to send ether value through a smart contract on the version of solidity 0.4. I know by experience that we can use: contract.deposit{value: 1 ether}(); from the version 0.6 ...
  • 457
1 vote
1 answer
3k views

What does msg.sender == tx.origin actually do? Why? [duplicate]

A lot of contracts use require(msg.sender == tx.origin) What is the purpose of it? When should you add this code? What difference does it make if the msg.sender is not a tx.origin? And in which cases ...
0 votes
1 answer
1k views

payable(msg.sender)

pragma solidity ^0.8.4; contract Contract { address payable public owner; constructor() public { owner=payable(msg.sender); } } msg.sender is of type address by default? so I ...
1 vote
1 answer
522 views

Who is msg.sender when function calls a function within the same contract?

So yeah, who is the msg.sender if a function calls another function within the same contract? contract A { function doSomething() { do2(); //msg.sender == the user } ...
0 votes
1 answer
236 views

How to Calculate Jager using msg.value on Binance Smart Chain?

Very quick and likely easy question here. I am trying to code a crowdsale contract that accepts BNB and returns a number of tokens to the sender. My transactions keep failing because it says the BNB ...
  • 21
2 votes
1 answer
2k views

Using different accounts for executing a function in solidity unit testing

I have written a smart contract and within which I have declared a payable function where everyone could send their funds to the contract. Once they have transferred their funds, they would have the ...
0 votes
0 answers
539 views

msg.sender and msg.value - do they work only for sent Etherum or do they work for ERC20 tokens sent to the contract too?

I'm starting to learn Vyper and I wanted to ask a question regarding msg.sender and msg.value If I created a simple contract that simply returns msg.sender and msg.value I understand that if I sent ...
1 vote
1 answer
667 views

Can someone sign a transaction and have someone else broadcast it and pay the transaction fees?

Can someone sign a transaction, maybe for sending funds or for smart contract interaction, and have someone else broadcast it and pay the transaction fees? Or is it that the signer of the transaction ...
  • 1,463
3 votes
1 answer
172 views

What is value of msg.sender when reading contract on etherscan or bscscan?

When I look at a contract on etherscan or bscscan, it is possible to read the contract, which basically just calls a public function of the contract. But what value is used for msg.sender when I read ...
  • 227
1 vote
1 answer
162 views

How to prevent front-running the salt when using CREATE2?

I was looking at Optionality's clone-factory, which is based off EIP-1167, and wondering whether it can be ported to use CREATE2. One concern is that a third-party could, in theory, "front-run&...
0 votes
1 answer
72 views

Sending tokens to and from a contract address

I have a contract that's responsible for distributing an ERC20 token to a list of addresses. In the contract there's a function that simplifies to something like: function sendTokenToAddresses(uint ...
  • 115
0 votes
1 answer
521 views

TypeError: Member "isContract" not found or not visible after argument-dependent lookup in address

pragma solidity ^0.8.4; This modifier: modifier onlyNotContract() { require(!msg.sender.isContract(), "Contracts are prohibited"); _; } Is generating this error: ...
  • 39
0 votes
1 answer
66 views

Get the sender address in ContractB when called from ContractA

I have 2 contracts A & B. A calls one of the methods from B. How do I get the caller address in that method of B? Usually msg.sender in A will give the address of caller but we cannot do the same ...
  • 359
0 votes
2 answers
64 views

Would an EOA's balance change within the same transaction?

I'm trying to understand various aspects of the micro-process of a transaction such as how msg.sender's balance is changed prior to and after a transaction is mined. Is the balance updated after the ...
  • 501
2 votes
3 answers
3k views

How can msg.sender == address(this)?

I know that msg.sender will be the address that connects to the contract. Address(this) is the current contract address Then == means it connects to itself. When using this condition in require, the ...
  • 79
1 vote
1 answer
167 views

Is there something in front of msg.sender?

Tx.origin is an old way of utilizing the handling address behind msg.sender. But let's say I, as a user, am calling a contract and that contract calls a contract. Is there a way for contract B... to ...