Friday, November 22, 2024

bitcoinjs – Monitoring incoming transactions utilizing nodejs and personal node

I have to confirm that person from my database has despatched btc to my pockets.

Ideally I need to generate a singular tackle for every person transaction after which observe all these addresses however I suppose it is going to be troublesome to implement as a consequence of tackle hole restrict, so I made a decision to simply ask customers for his or her bitcoin tackle after which anticipating tx with funds switch from that tackle to my pockets so I can confirm funds had been despatched by them.

I’ve personal bitcoin node which I need to use for monitoring all of the transactions to my pockets.

So to illustrate I need to observe all txs simply to my pockets tackle.

I used to be following the information implement this with ZEROMQ. I’ve up to date bitcoind config file with to can pay attention for uncooked txs through zeromq.
There are my nodejs code:

const bitcoin = require('bitcoinjs-lib');
const zmq = require('zeromq');

const sock = zmq.socket('sub');
const addr="tcp://127.0.0.1:3000";

module.exports = perform (app) {

    sock.join(addr);
    sock.subscribe('rawtx');

    sock.on('message', perform (matter, message) {
        if (matter.toString() === 'rawtx') {
            let rawTx = message.toString('hex');
            let tx = bitcoin.Transaction.fromHex(rawTx);
            let txid = tx.getId();

            const tackle = bitcoin.tackle.fromOutputScript(tx.outs[0].script, bitcoin.networks.testnet);

            console.log("tackle ", tackle)
            console.log('acquired transaction', txid, tx);
        }
    });
}

As I perceive, once I connect with node in stay community from this code, I will be notified about all txs which are taking place within the community?

How can I validate transactions with transferring funds solely to my pockets and decode tackle from which funds had been transferred?

Are there some straightforward methods to implement this and possibly some code/mission examples?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles