[Ethereum] How to list transactions from account address

accountsaddressesinternal-transactionstransactions

I have a small service where people can exchange cryptocurrencies.
Every user has its own Bitcoin, Litecoin, etc address for balance deposit.
Now I want to add Ethereum. So I thought I will create account for every user and then check for incoming transactions.
But as I understood I can't get a list of transactions from account address.
This is weird. Even in the Mist wallet I don't see where ether comes from.
Only way to get transactions is to check some 3rd party blockchain explorer.

Also as I understood the proper way will be to create smart contract, because it has necessary API. But I can't create contact for each user.

Maybe I need to create only 1 contract that will "redirect" ether to my main account, but this is not very user friendly, because the user will be asked to add some extra data to the transaction so that I could understand who is who.

Any advise will be helpful.

Best Answer

If I understand your question correctly you want to be able to see who has deposited Eth to your contract address. This is what event logs are for.

(1) Create a contract where there is an event every time there is a transaction. e.g something like:

contract someContract {   

    address public owner;

    // Set the owner of the contract to be the creator of the contract i.e. you
    function someContract() {
        owner = msg.sender;
    } 

    // This is an event 
    event DepositMade(address _from, uint value);
    event WithdrawalMade(address _to, uint value);

    //Catch all function 
    function() {
        // generate an event when someone sends you Eth
        if (msg.value > 0)
            DepositMade(msg.sender, msg.value);
    }

    // Only the owner of the site can withdraw Eth
    modifier admin { if (msg.sender == owner) _ }

    function withdraw(uint amount, address recipient) admin {
        if(recipient.send(amount))
            WithdrawalMade(msg.sender, msg.value);
        else throw;
    }
}

The important bits are defining an event type event DepositMade(address _from, uint value) and generating an event when something happens DepositMade(msg.sender, msg.value);these events are stored in the event log associated with the address of the deployed contract instance.

(2) You retrieve the events on this contract using rpc eth_newFilter or web3.eth.filter e.g something like:

var filter = web3.eth.filter({fromBlock:0, toBlock: 'latest', address: contractAddress, 'topics':['0x' + web3.sha3('DepositMade(hexstring,uint256)')]});
filter.watch(function(error, result) {
   if(!error) console.log(result);
})
Related Topic