1

i'm new to solidity and am trying to learn writing some contract on my own. I've came across an ethereum forwarding contract where eth sent to this contract address gets automatically forwarded(sent) to the destination address.

pragma solidity ^0.4.21;

contract Forwarder {

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

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

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

  function flush() public {
    emit LogFlushed(msg.sender, address(this).balance);
    destinationAddress.transfer(address(this).balance);
  }

}

My questions are:

  1. How can i write a function to automatically increment the balance of the ethereum deposited into this contract address for tracking purposes?
  2. How can i call this function from web3?

All help is appreciated.

  • Sorry, but I cannot really understand what are you looking for. can you explain better, what do you mean by "the balance of the ethereum deposited into this contract address"? Do you mean the balance or you would like to know "how much ether" it has managed during its lifetime? – Briomkez Sep 2 '18 at 19:23
  • Would like to get all the deposit history into this contract address. Realised that i could use the web3 events and filter, but i'm clueless at the moment on how to use them unless i take a couple of hours to figure this out. – Zinxer Sep 2 '18 at 19:37
  • 1
    That's what blockchain is for. Store this information on the contract's storage would be a waste of money and it is redundant. Yes, you should keep track of the different events. – Briomkez Sep 2 '18 at 19:40
  • Hmm, but doesn't ERC20 standard tokens keep a record of balances as well for each addresses? I understand that gas is paid during transfer. – Zinxer Sep 3 '18 at 2:50

Your Answer

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

Browse other questions tagged or ask your own question.