1

I coded a small smart contract with 1 functions, the problem I am facing is when I call that function from the explorer or my front-end, the msg.sender is always 0x00000...

I deployed this with the goerli testnet and I am also logged in with the same testnet account.

Try the openCall read function on this contract - https://thirdweb.com/goerli/0x2D8Fccd58DdDe7583d8ab28A5a0A40877f543d59/explorer

This is the contract:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;

contract Receipt {
    event Deployed(address indexed deployer);

    constructor() {
        emit Deployed(msg.sender);
    }

    // Open function see if current user is admin
    function openCall() public view returns (string memory, address) {
        return ("Called Open", msg.sender);
    }
}

enter image description here

2 Answers 2

2

It is because you are calling a publicly available view function. This call to a contract is 'free' and therefore can be sent without sending a transaction to the contract address.

If the function required a transaction, sender would not be '0x0'.

1
  • Thank you! I did not know a call does not pass the address (or transaction). Makes sense Mar 5, 2023 at 15:20
2

As 'House Y' mentioned, view function doesn't send transaction and doesn't need any fee, so this kind of functions doesn't need any signer and when there is no signer, there is no address. I hope it make sense.

1
  • Yup makes sense now. Thanks! Mar 5, 2023 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.