![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@bitcoinerlab/explorer
Advanced tools
Bitcoin Blockchain Explorer: Client Interface featuring Esplora and Electrum Implementations.
@bitcoinerlab/explorer
is a library that provides a common interface for interacting with various blockchain explorer services like Esplora and Electrum. The library aims to standardize the way developers access the functionality provided by these services and enable easy integration with the @bitcoinerlab
ecosystem.
npm install @bitcoinerlab/explorer
Depending on the specific client you wish to use (Electrum
or Esplora
), there are different considerations to keep in mind.
Install Required Modules:
npm install @bitcoinerlab/explorer react-native-tcp-socket
Eject from Expo (if in use):
npx expo prebuild
cd ios && pod install && cd ..
Shim net
& tls
by adding these lines to your package.json
:
"react-native": {
"net": "react-native-tcp-socket",
"tls": "react-native-tcp-socket"
}
Set Up Global Variables:
Create an electrumSupport.js
file that you must import at the entry point of your application (before any other imports). This file should contain the following code:
global.net = require('react-native-tcp-socket');
global.tls = require('react-native-tcp-socket');
If you're integrating the Esplora client within a React Native environment, you might encounter the error "URL.protocol is not implemented"
. This arises because React Native doesn't have a full implementation of the browser's URL
class.
To address this:
Install the URL Polyfill:
npm install @bitcoinerlab/explorer react-native-url-polyfill
Integrate the Polyfill:
At the top of your entry file (e.g., index.js
or App.js
), include:
import 'react-native-url-polyfill/auto';
This polyfill will provide the missing URL
functionalities in React Native, ensuring the Esplora client operates without issues.
This library provides a unified interface for interacting with Bitcoin Blockchain explorers. Currently, it supports two popular explorers: Esplora and Electrum.
The following methods are shared in all implementations:
connect()
: Establish a connection to the server.close()
: Terminate the connection.fetchAddress(address: string)
: Retrieve the balance and usage details of a Bitcoin address. This returns an object with:
used
: A boolean that denotes if the address has received any coins in the past, even if its current balance is zero.balance
: The present balance of the address, measured in satoshis.fetchScriptHash(scriptHash: string)
: Acts similar to fetchAddress
but for a script hash.fetchTxHistory({ address?: string; scriptHash?: string; })
: Acquires the transaction history for a specific address or script hash. The function returns a promise that resolves to an array of transaction histories. Each entry is an object that contains:
txId: string
blockHeight: number
irreversible: boolean
Note: They're typically returned in blockchain order. But there's a known issue with Esplora where transactions from the same block might not maintain this order.fetchFeeEstimates()
: Obtain fee predictions based on confirmation targets. It returns an object where keys are confirmation targets and values are the projected feerate (measured in sat/vB).fetchBlockHeight()
: Determine the current block tip height.push(txHex: string)
: Submit a transaction in hex format.In this section, we demonstrate how to use the existing implementations, Esplora and Electrum, provided by this library. You can also create your own implementations following the Explorer
interface to work with other services.
Here's an example of how to use the EsploraExplorer
class:
import { EsploraExplorer } from '@bitcoinerlab/explorer';
(async () => {
const explorer = new EsploraExplorer({ url: 'https://blockstream.info/api' });
// Connect to the Esplora server
await explorer.connect();
// Fetch UTXOs of an address (returns a Promise)
const utxos = await explorer.fetchUtxos(
'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq'
);
// Fetch address information (returns a Promise)
const addressInfo = await explorer.fetchAddress(
'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq'
);
// Fetch fee estimates (returns a Promise)
const feeEstimates = await explorer.fetchFeeEstimates();
// Close the connection
explorer.close();
})();
To use the ElectrumExplorer
class, follow a similar pattern but with different constructor parameters:
import { ElectrumExplorer } from '@bitcoinerlab/explorer';
async () => {
const explorer = new ElectrumExplorer({
host: 'electrum.example.com',
port: 50002,
protocol: 'ssl'
});
//...
};
Note that the EsploraExplorer
and ElectrumExplorer
classes accept optional parameters irrevConfThresh
and maxTxPerScriptPubKey
, which correspond to the number of confirmations required to consider a transaction as irreversible (defaults to 3) and the maximum number of transactions per address that are allowed (defaults to 1000). You can set a larger maxTxPerScriptPubKey
if you expect to be working with addresses that have been highly reused, at the cost of having worse performance. Note that many Electrum servers will already return at most 1000 transactions per script hash anyway, so consider using an Esplora server or an Electrum server that supports a large number of transactions if this is of your interest.
To generate the API documentation for this module, you can run the following command:
npm run docs
However, if you'd prefer to skip this step, the API documentation has already been compiled and is available for reference at bitcoinerlab.com/modules/explorer/api.
The project was initially developed and is currently maintained by Jose-Luis Landabaso. Contributions and help from other developers are welcome.
Here are some resources to help you get started with contributing:
To download the source code and build the project, follow these steps:
git clone https://github.com/bitcoinerlab/explorer.git
npm install
npm run build
This will build the project and generate the necessary files in the dist
directory.
Before finalizing and committing your code, it's essential to make sure all tests are successful. To run these tests:
127.0.0.1:8080
.To streamline this setup, you can use the Docker image, bitcoinerlab/tester
, which comes preconfigured with the required services. The Docker image can be found under Dockerfile for bitcoinerlab/tester. When you run the test script using:
npm test
it will automatically download and start the Docker image if it's not already present on your machine. However, ensure you have the docker
binary available in your path for this to work seamlessly.
This project is licensed under the MIT License.
FAQs
Bitcoin Blockchain Explorer: Client Interface featuring Esplora and Electrum Implementations.
We found that @bitcoinerlab/explorer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.