22

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.

8
  • 2
    My advise is to up-vote #1897 on github. Commented Mar 26, 2016 at 12:00
  • 1
    @NikhilM, done. Commented Mar 26, 2016 at 15:12
  • 1
    ethereum.stackexchange.com/questions/3417/… is also helpful to understand. Commented Nov 26, 2016 at 6:02
  • 1
    This thread may also be useful: ethereum.stackexchange.com/questions/2531/… Commented Apr 5, 2017 at 7:16
  • 1
    Sorry i cannot comment so i'll ask here. @dmxhZGp1c2hh did you find a solution? If yes please post it here. Commented Jul 19, 2017 at 8:38

3 Answers 3

10

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); }) 
14
  • 3
    Thank you, but I am asking about regular account, not contract. Commented Mar 26, 2016 at 15:13
  • the user doesn't need to know the difference. No data is required they just send Eth to an address and the catch all function() is fired Commented Mar 26, 2016 at 15:15
  • So if I have 1000 users I need to create 1000 contracts? Commented Mar 26, 2016 at 15:21
  • 7
    This is a nice piece of code, but why waste eth logging information already logged in the blockchain? Commented Jun 8, 2017 at 6:21
  • 1
    This is not good for business solution. We talk real money, so it must be foolproof. Clients making deposits from exchanges have no idea from which address transactions are sent, multiple clients can use same address. Wallets have no options to include arbitrary data. Address per client must be generated and funds must be then forwarded to common account. There fore we need list of incoming (and outgoing - which we have) transactions. Commented Jan 25, 2018 at 12:00
4

You could try using the etherchain.org GetAccountTransactions API that is documented at https://etherchain.org/documentation/api/ .

Eg: https://etherchain.org/api/account/0xbeef281b81d383336aca8b2b067a526227638087/tx/0 will give you the transactions as displayed at https://etherchain.org/account/0xbeef281b81d383336aca8b2b067a526227638087#txsent

Etherscan also has some documented APIs - https://etherscan.io/apis. Here's the equivalent API call for the same transaction data for the account as above. http://api.etherscan.io/api?module=account&action=txlist&address=0xbeef281b81d383336aca8b2b067a526227638087&sort=asc

3
  • 2
    I think dmxhZGp1c2hh dos not want to use third party service Commented Oct 22, 2017 at 22:51
  • Etherchain.org is often in "limited feature mode" and unreliable. Etherscan.io has an API limit of 5 per second, with no way to increase. That's abysmal and borderline useless. One shouldn't trust 3rd parties for this information, no matter how trust-worthy they seem. Additionally, neither of these show token transfers, which seems to be an entirely different beast. Commented Jan 20, 2018 at 6:03
  • @EvilJordan I agree, even if it works fine now days, I don't want my business depend on it. I did that mistake with btc blockchain.info, which had many problems before, when btc was getting popular. Commented Jan 25, 2018 at 12:02
0

Ethplorer provides a good API for many cases.

Get address info

Get address history

and many others. enter image description here

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.