I have a library that is making a call to an external address like this


This callData is calling a function of another contract that is utilizing the msg.sender value. I seem to be getting some errors, so I am wondering who exactly is the msg.sender if a call is made from inside of a library.

Roughly the order of transactions is:

My contract calls a library function => library calls external contract function => external contract uses msg.sender to do something.

  • I think that it depends on whether the library is deployed as a standalone library or it is inlined. In the latter case, I am sure that it is the contract importing the library which is msg.sender. In the former, I don't know. Sep 15, 2021 at 20:52

1 Answer 1


Suppose contractA calls a function in libraryB, and it calls a function f() in contractC.

Then the msg.sender of function f() should be contractA. However, the msg.sender of function doSomething() should be your calling EOA.

Infact, contractA calling libraryB should be consider as delegateCall and the latter one should be consider as call.

I have made a small example to test. Here it is:

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

contract C {
    event testEvent(address msgSender, address from);
    function f() public payable {
        emit testEvent(msg.sender, address(this));

library LibB {
    event LibEvent(address msgSender, address from);
    function doSomething(address c) public {
        emit LibEvent(msg.sender, address(this));

contract A {
   using LibB for address;
   address c = 0x7EF2e0048f5bAeDe046f6BF797943daF4ED8CB47; // write your own c address here
   constructor() {

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.