0

I need to constantly keep running some code to detect if someone has in the past minute sent some ether/token to a lot of addresses, is there better way to do than https://ethereum.stackexchange.com/a/3478/39163 that gets all transcations to one address and then somehow compare the current time with transaction time to determine if its just happened?

0

Rather than pull data every minute, we can use a subscription to get push requests to monitor an address. You can do this using Web3.js 1.0 through web3.eth.subscribe: subscribe("logs")

var web3 = new Web3(Web3.givenProvider || 'wss://mainnet.infura.io/ws');

var subscription1 = web3.eth.subscribe('logs', {
    address: '0x06012c8cf97BEaD5deAe237070F9587f8E7A266d'
}, 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)
            }
        })
})

This subscription should be listening to the blockchain for any transactions to an address which has a value > 0. These should appear nearly real time.

Ether sent from 0xcdF5EAD1c329584d835C2Bf6f828C5cAb9B611E6 to 0xb1690C08E213a35Ed9bAb7B318DE14420FB57d8C

Ether sent from 0x9c539429C2caD0c58aeCe00C13B5B7A5977217fb to 0xb1690C08E213a35Ed9bAb7B318DE14420FB57d8C

Ether sent from 0xcdF5EAD1c329584d835C2Bf6f828C5cAb9B611E6 to 0xb1690C08E213a35Ed9bAb7B318DE14420FB57d8C

...

0

AFAIK, there is no fool-proof way to do this, the best you can do is to run a full node and keep checking unconfirmed balances of the required addresses. Few caveats are;

  1. Node sync delay
  2. 3rd party client txn submit delay.

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.