0

I have a website where I need to receiving ETH payments from my users. I have a smart contract that successfully forwards any transactions sent to it to another address (my storage account), and each user gets their own unique smart contract to send to so we know who to credit:

pragma solidity 0.4.21;

contract Forwarder {

  address public destinationAddress;
  event LogForwarded(address indexed sender, uint amount);

  function Forwarder() public {
    destinationAddress = msg.sender;
  }

  function() payable public {
    emit LogForwarded(msg.sender, msg.value);
    destinationAddress.transfer(msg.value);
  }

}

Is it possible for me to subscribe to all transfers into my storage account, and view the smart contract that created the transfer so that I can associate it with a user on my website and credit them? If not, is it at all possible to do what I'm trying to do without subscribing to each smart contract individually?

  • I'm not sure I understand the problem correctly. You are already emitting an event which includes the msg.sender - this is the address where the transaction comes from. Isn't that what you need? Then you just need to subscribe to those events – Lauri Peltonen May 15 at 7:26
0

So, from what I have understood is that you want to know the user account which triggered the transaction rather than the smart contract account.

One thing you have to understand is that:

msg.sender provides you with the immediate account address which initiated the transaction.

tx.origin provides you with the account address that started the transaction irrespective of the stack of the contracts invoked.

Let's understand it with an example: if A transacted with B which is smart account which in turn triggered the transaction that transferred some Ether to your storage account. So,

msg.sender will provide you the address of B

tx.origin will provide you the address of A since it was the one from where the transaction originated.

But, there are security issues with the tx.origin so please check them out before using it in your contract. You can check this link to know more about the tx.origin related attacks and security flaws

I hope this answers your query.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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