1

I wrote some simple code with web3js to track an address/account's transaction in real-time. It works, but I think it is in poor performance or could consume too much cpu resources.

sample code

 let filter = web3.eth.filter("latest");
 filter.watch(function(error, result) {
    if (!error) {
      //tracking start in 12 blocks earlier .
      var earlierNumber = web3.eth.getBlock(result).number - 12;
      var confirmedBlock = web3.eth.getBlock(earlierNumber ) ;

      if (confirmedBlock.transactions.length > 0) {
          confirmedBlock.transactions.forEach(function(tx) {
             if ( tx.to == address ) {                     
                var depositAmount =  web3.fromWei(tx.value.toNumber(), 
                "ether" )
                console.log("address: " +address+ " deposit amount:  "+depositAmount+ " ETH." ) ;                     
              }     
          }) 
       }
     }  
  })  

How could those large scale trade or exchange platform track huge amount of account' transaction accurately ? I find much good project such as MetaMask-token-tracker ,on Git. How about it? Or any open source to recommend?

0

The exchanges don't make the transactions between blockchain accounts. Furthermore, the transactions aren't even visible in the blockchain. If you buy coin A with coin B, the exchange just shuffles numbers around inside their own databases and nothing is published to the blockchain. This makes perfect sense resource-wise: changing a few database values is a lot cheaper and faster than publishing transactions to a blockchain.

In theory, ERC20 token balances are tracked only within the token contract. But when you exchange tokens in an exchange, it's also just shuffling numbers in their databases and according to the blockchain the tokens never move anywhere.

Correct transactions are published only when you withdraw/deposit assets from the exchange. Otherwise everything the exchange owns (coins & tokens) are just stored in their own wallets.

  • Maybe my question is a little confusing . Actually , I just want to know ,how that large trade platform to detect or accept deposits action from their client in a real-time . The sample code works as a block-listener and tracking every deposit transaction correctly on expected . But it looks like need much overhead to keep monitoring . Is there any cheap way alternative ? Or those trade service, Binance , Bittrex just to build powerful server to do it . – Kimmy Apr 7 '18 at 5:40
  • Ah, yes, sorry, I misinterpreted your question. Then my answer is not so relevant anymore, but I don't have an answer for your real question either. – Lauri Peltonen Apr 7 '18 at 9:15

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.