4

Building a TipFaucet for tipping a dev.

Using this contract, is it possible to look up how much has been payed through the contract?

contract TipFaucet {

    modifier isDev { if (msg.sender != // insert address here) { throw;} else { _;}}

    function withdraw() isDev {
        msg.sender.send(this.balance);
    }
}
1

The easiest way to look up how much has been paid through the contract would be to add some variables that will keep track of the amounts received and paid:

contract TipFaucet {

    uint public received;
    uint public paid;

    modifier isDev { if (msg.sender != // insert address here) { throw;} else { _;}}

    function withdraw() isDev {
        paid += this.balance;
        msg.sender.send(this.balance);
    }

    function () {
        received += msg.value;
    }
}

You should now have a received() and paid() constant function that you can call and this should provide you with the results you are looking for.

You could log events when the withdraw() method is executed, but you will have to total the amounts across all the events. See How do I retrieve the Voted events from The DAO for an example of how to retrieve the events.

Or you could scan the transactions executed against this contract and total only the transactions that execute the withdraw() method.



App To View Total Ethers Process

The easiest way to view the total ethers processed by this contract would be to watch the contract in the Ethereum Wallet or Mist application.

You can then call the paid() method to get the figures you are looking for.

Here is a screen shot from the Ethereum Wallet watching a contract where the public variables are visible in the Watch Contract screen:

enter image description here

In your case, you should see a Paid field with the total ethers paid being displayed below.

3
  • Thanks, that was how I would have solved it as well. Just thought it could be even easier if there were third party services for it. Oct 2 '16 at 0:15
  • You can use EtherScan's Read Contract tab to view your variables. You can easily read totalSupply and sealed in etherscan.io/address/… . This is the ExtraBalToken contract described in ethereum.stackexchange.com/questions/7265/… .
    – MELVIS.ETH
    Oct 2 '16 at 0:20
  • 1
    Ah I was aware of that too. Thought that total-ether-processed might be readable without in-contract variables. blockchain.info shows total BTC processed by an account. Of course with in-contract storage it might be easier to just use that. Oct 2 '16 at 0:26

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.