TransWikia.com

How to find which smart contract forwarded funds to account

Ethereum Asked on December 23, 2021

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?

One Answer

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.

Answered by Aditya Sharma on December 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP