I am new to developing smart contracts and have had some trouble trying to troubleshoot a solution to this problem.

I have two smart contracts...

Contract X: (The bank - Balance 100 ETH)

contract X {
   function transfer(address dest){


Contract Y: (The Forwarder - Balance ZERO ETH)

contract Y {
  function < somehow call x.transfer >
  <set x.msg.value to some number ignoring the actual msg.value of the call>

Contract X will store some funds and contract Y will be used to call the 'transfer' function of contract X and provide a destination address to transfer funds to. The problem I am having is that I don't know how (or if it is possible) to set the value of 'msg.value' in contract X from the function call in contract Y.

Currently 'msg.value' in contract X is only ever zero since contract Y will not be used to store any funds (besides small amounts of wei for gas).

Does anybody know of a way to parse a specified 'msg.value' over a function call?

Side note: There are more to these contracts although it's not necessary to include them here.

Any help is greatly appreciated!


The desired result would look something like this:

contract Y > contract X:

  • msg.value for this transaction will be zero (no funds sent from Y to X)
  • Y will supply dest address for contract X's transfer function
  • Y will supply msg.value for contract X's transfer function (This is my main isssue)

contract X > Destionation (dest) address:

  • transfer function will use the msg.value and dest values provided by contract Y above

  • msg.value will never be zero

I guess the question is really if it is possible to parse a msg.value to the external contract (contract X) to use as the msg.value for X's transfer - that is not the zero msg.value from the the Y to X?

1 Answer 1


To send funds in a function call to another contract you can use something like this:

contract X {
  function transfer(address dest, uint amount) public { ... }
contract Y {
  function take() public payable {
    // Reference an existing contract at an address
    X ref = X(addressOfX);
    // or if creating a new instance at a new address: X ref = new X();
    ref.transfer(destAddress, msg.value);

That example is missing stuff, but it contains the essentials.

  • Thanks Lauri, although in this case contract Y won't be holding any funds. So it won't be sending any ether to contract X. I have edited the question above to make the desired result more clear.
    – Renoi
    Commented Jan 19, 2021 at 23:22
  • edited answer now Commented Jan 20, 2021 at 6:22

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.