bitpay – Monitoring Bticoin Cash Wallet Transactions

I am developing a simple script that can run as a background task and monitor the transaction for a Bitcoin cash wallet. I have the following setup:

var PROTO_PATH = __dirname + '/bchrpc.proto';
var fs = require('fs');

var grpc = require('@grpc/grpc-js');
var protoLoader = require('@grpc/proto-loader');
var packageDefinition = protoLoader.loadSync(
    {keepCase: true,
     longs: String,
     enums: String,
     defaults: true,
     oneofs: true
var pb = grpc.loadPackageDefinition(packageDefinition).pb;

var client = new pb.bchrpc('', grpc.credentials.createSsl());

// Build TransactionFilter & setup live transaction stream
var transactionFilter = pb.TransactionFilter
transactionFilter.all_transactions = true
transactionFilter.addresses = ('<Address>');

var subscribreTransactionsRequest = pb.SubscribeTransactionsRequest;
subscribreTransactionsRequest.include_mempool = true;
subscribreTransactionsRequest.subscribe = transactionFilter;

var stream = client.SubscribeTransactions(subscribreTransactionsRequest)

stream.on('data', function(message) {
    console.log('New Transaction');
    var tx = message
    const { type } = tx;
    switch(type) {
        case 'UNCONFIRMED':
            const h1 = tx.unconfirmed_transaction.transaction.hash;
            fs.writeFileSync('unconfirmed.txt', `${h1.toString('hex')}n`, { encoding: 'utf-8', flag: 'a+' });
        case 'CONFIRMED':
            const h2 = tx.confirmed_transaction.transaction.hash;
            fs.writeFileSync('confirmed.txt', `${h2.toString('hex')}n`, { encoding: 'utf-8', flag: 'a+' });
stream.on('status', function(status) {
stream.on('end', function(status) {

I copied the snippet from bchrpc examples and modified it to listen to a test address I generated using Bitpay wallet. I tried to connect to the address using the code above. When I run the code, the program listens for incoming transactions. To test the script, I added some funds from test faucet. The funds were added to the wallet after about ten minutes but the script did not do anything. My expectation was that the data event will be fired and there will be some output in the TXT files (or some error). But, none of that happened.

I am fairly new to this so, I am not sure what I am missing or how else I should set this up. Some help or guidance will be highly appreciated. Thanks.


After reviewing the bchrpc.proto file, I realized that my code was somewhat wrong. I changed to SubscribeTransactions and also added the address to TransactionFilter. However, now I get an error that decoded address is of unknown format.