5

I've recently found out, that there's no convenient way to monitor transactions to 'externally owned account' generated by some contract. I went to various forums and ethereum bugtrackers for an answer and saw lots of requests to add some API calls to list all transactions, normal and contract invoked. Some of the people described real situations when they've lost ETH because the exchange they used didn't support such internal transactions. But in all cases eth developers said the same - 'exchange developers don't understand ethereum basics, they should use contracts instead of EOAs'.

OK, I tried to realize, what they should've done. Using EOA it's really simple - generate new account, give it to user and wait for some transactions. As I see it, using simplest contracts you need to provide your user 2 entities - address of your contract and some encoded data, that will contain method signature and generated user id, and then you just listen to logs. From user's perspective I see it quite inconvenient to operate with 2 instances if I just want to deposit money on my account - it becomes much more error prone. And I'm not sure, all users' contracts will support sending to such exchange contracts without additional coding.

Is there any obvious scenario, that I'm missing?

Sorry for the long question and possible duplicate, but I couldn't find any examples on how to do it right.

EDIT: Don't have enough reputation to comment Tjaden's answer (thanks for it, btw), so 'commenting' here. Yes, I thought of this version too, but forgot to add it in original question. Using fallback function is nice and easy, BUT - as I understand it - in that case you should create a contract for each user, which results in 2 problems:
- spending money each time (not much, but still - paying just for account creation doesn't seem very fair)
- you should send each contract to blockchain and then wait some time for it to be confirmed before providing a user with his address.

Does the majority of ethereum community think the same way as Tjaden?

6

The user doesn't need to do anything extra, since all contracts have a fallback function that is called when it recieves a transaction with no data. for example:

contract DepositAddress{
    string username;
    address exchange;
    event ReceivedEther(uint amount, uint time, string username);

    function DepositAddress(string _username, address _exchange){
        exchange =_exchange;
        username = _username;
    }

    function(){
        ReceivedEther(msg.value,block.timestamp,username);
        exchange.send(msg.value);
    }
}

Then any time a user sends ether to their deposit address, it will emit an Event, and forward the ether to the main exchange account.

Alternatively, and probably preferably, you could do all of the accounting within a smart contract. When a user deposits ETH, their account is debited with a token. When they use some of their balance, they spend the token. This way, you don't need logs at all. You just use the current amount of tokens they possess.

  • I'm still very new to contracts but where is the event's ReceivedEther() body implemented? – Sebi Jun 10 '16 at 7:26
  • 1
    There is no function body, it's automatically generated by the event declaration. Calling RecievedEther simply writes to the log in an easy format – Tjaden Hess Jun 10 '16 at 14:34

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.