1

I just started playing arround with blockchain development and the use of web3 so I have more questions than my fingers are able to type, hope some of you are able to answer the first one I have.

What I want to archieve is following: Subscribe to an address (wallet) and then stream all transactions going out- or going in for this address.

I also want to know for example, if the wallet makes an outgoing transaction to another address, what Token had been sent. I hope this makes sense or is even possible.

Like I want to know if wallet A sends funds to wallet B and what kind of token had been sent.

This is what I got so far, need help to get in the right direction for the rest of what I am trying to do.

var subscription1 = web3.eth.subscribe('logs', {
    address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'
}, function (error, result) {
})
.on("data", function (log) {
    //console.log(log);
    web3.eth.getTransaction(log.transactionHash)
        .then(function (transaction) {
            console.log(transaction)
            if (transaction.value > 0) {
                console.log("Ether sent from " + transaction.from + " to " + transaction.to)
            }
        })
})

I am also unclear about, why the subscription outputs a console.log at the very beginning containing an transaction array and other information, as I expected to only receive data in the "on data" event.

Thank you for reading, hoping someone has the patient to help me out stepping into the topic.

Regards

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.