Delegatecall

delegatecall is a low level function similar to call.

When contract A executes delegatecall to contract B, B's code is excuted

with contract A's storage, msg.sender and msg.value.

pragma solidity ^0.5.11;

// Firts deploy this contract
contract B {
  uint public n;
  address public sender;
  uint public value;

  function setN(uint _n) public payable {
    n = _n;
    sender = msg.sender;
    value = msg.value;
  }
}

contract A {
  uint public n;
  address public sender;
  uint public value;

  function delegatecallSetN(address b, uint _n) public payable {
    // A's storage is set, B is not modified.
    (bool success, bytes memory returnData) = b.delegatecall(
      abi.encodeWithSignature("setN(uint256)", _n)
    );
  }
}

Try on Remix