ruimarinho / bitcoin-core

A modern Bitcoin Core REST and RPC client.
482 stars 188 forks source link

RpcError: Not Found #58

Closed tolak closed 6 years ago

tolak commented 6 years ago

The problem is when i use bitcoin-core api, such as getinfo(), getBalance() and they all work fine. But there are three api can not work. They are getTransactionByHash() , getBlockByHash() and getBlockchainInformation(). They all throw error: "RpcError: Not Found". The txid and the block-hash are all exist and correct. I used "curl" to make a rpc call and all of it returned what i want.

Here is my code


getTransactionByHash(txid) {
    if (typeof this.client === 'undefined' || !this.client) {
        return Promise.reject(new Error('RPC client was not defined'));
    }

    return this.client.getTransactionByHash(txid).then(res => {
        // transaction should have keys('blockhash', 'locktime', 'hash', 'size', 'txid', 'version', 'vin', 'vout', 'vsize');
        const transaction = res;
        return Promise.resolve(transaction);
    });
}

getBlockByHash(hash) {
    if (typeof this.client === 'undefined' || !this.client) {
        return Promise.reject(new Error('RPC client was not defined'));
    }

    return this.client.getBlockByHash(hash, { extension: 'json' }).then(res => {
        // block should have keys('bits', 'chainwork', 'confirmations', 'difficulty', 'hash', 'height', 'mediantime', 'merkleroot', 'nextblockhash', 'nonce', 'size', 'strippedsize', 'time', 'tx', 'version', 'versionHex', 'weight');
        const block = res;
        return Promise.resolve(block);
    })
}
ruimarinho commented 6 years ago

@tolak I'm sorry but I'm unable to replicate this issue. I've started a new (clean) bitcoin node, did a generate 50, then a curl to http://localhost:18333/rest/chaininfo.json. Grabbed the bestblockhash hex, tried executing getBlockByHash(hash) and the client returned successfully. Then from that call, I grabbed a txid. Requested getTransactionByHash(txid) and the response was successful again.

Comparing the curl to the client (node) request, both reply equally and to the same endpoints. If you want to double check yourself, run your script with NODE_DEBUG=request node script.js.