I'm trying to build an indexer for the EVM chains using the logs to read the ERC20 "transfers"
and I have the following question:

Some transactions (tx's) have logs with multiple deposits/withdrawals.
Now, sometimes all the deposits/withdrawals go to the tx.from / sender and sometimes most of them go to the tx.to or some other party (depends on the contract of-course).

My question is whether I can determine somehow to whom the deposit/withdrawal actually went from the logs ?

For example see the following, it has 2 withdrawals logs: https://bscscan.com/tx/0xc880ffcd92b6a150f0a6083a02cdd31c49b6142817b99c4eea6ae32d49517624#eventlog

Thanks in advance ^_^

  • 1
    You can find an example here: github.com/tradingstrategy-ai/eth-hentai/blob/master/eth_hentai/… Mar 16, 2022 at 21:27
  • 1
    @MikkoOhtamaa according to that, it looks only for the Transfer events... So you want to tell me that when a deposit or a withdrawal events are emitted there's a sub transaction (thats should be visible in the logs anyway if I real All the Transfer logs) ? Mar 17, 2022 at 8:43
  • 1
    @MikkoOhtamaa - See this example with 2 withdrawals in the logs - bscscan.com/tx/… Mar 17, 2022 at 8:46
  • If there multiple deposit / withdrawals they are all matches by corresponding transfer events. Mar 17, 2022 at 10:05
  • @MikkoOhtamaa so they create sub transactions? And if i read all the Transfer logs I can neglect the deposit/withdrawal logs ?! Mar 17, 2022 at 10:52

2 Answers 2


If you just want to do this for some tokens in particular (Highly recommended), you just need to set up listeners, they are the most efficient way, and you can even set up filters to listen only when the parameters match something in particular.

First we create the instance

var yourContractInstance= new web3.eth.Contract(erc20ABI,contractAddressYouWantToMonitor);
    filter: {myIndexedParam: [20,23], myOtherIndexedParam: '0x123456789...'}, // Using an array means OR: e.g. 20 or 23
    fromBlock: 0
}, function(error, event){ console.log(event); })
.on("connected", function(subscriptionId){
.on('data', function(event){
    console.log(event); // same results as the optional callback above
.on('changed', function(event){
    // remove event from local database
.on('error', function(error, receipt) { // If the transaction was rejected by the network with a receipt, the second parameter will be the receipt.

// event output example
> {
    returnValues: {
        myIndexedParam: 20,
        myOtherIndexedParam: '0x123456789...',
        myNonIndexParam: 'My String'
    raw: {...}

The return values will contain the from (Who sends the tokens), to (Who receives the tokens) and value (amount of tokens being sent) in that order.

Now, if you want to monitor this for all tokens, prepare to have really powerful expensive infrastructure and keep in mind that 90%+ of the data you store will never be used, but you can do it by listening to all the logs for all the transactions using the subscribe functionality

var subscription = web3.eth.subscribe('logs', {
    address: '0x123456..',
    topics: ['0x12345...']
}, function(error, result){
    if (!error)

// unsubscribes the subscription
subscription.unsubscribe(function(error, success){
        console.log('Successfully unsubscribed!');

You can use the search docs here to find examples and more details on the snippets https://web3js.readthedocs.io/

  • I meant how to understand them... 🤦‍♂️ Mar 23, 2022 at 12:48
  • You can understand all logs topics and data if we know to contract all events and decode according it. Mar 23, 2022 at 12:52
  • As I said, "The return values will contain the from, to and value in that order." If you read them like this, the json you get will even include the variable names as "from, to, amount" or "_from, _to, _amount" Mar 23, 2022 at 12:53
  • @AkshayTarpara did you read the question or the comments/conversation beneath it ? Mar 24, 2022 at 10:14
  • @EnriqueAlcázarGarzás did you read the question or the comments/conversation beneath it ? Mar 24, 2022 at 10:15

You can determine withdraw and transfer event using bscscan api. When smart contract emit the event always generate same topic ID. You can refer the bsc api docs, It's give the all logs with given range of blocks. This api give only first 1000 transaction of block range so according your use you narrow down the filter.

Try this:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.