Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including bitcoin-util with all npm packages installed. Try it out:

var bitcoinUtil = require("bitcoin-util")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

bitcoin-util v2.0.3

Utility functions for Bitcoin hashes and targets

bitcoin-util

npm version Build Status Dependency Status

Utility functions for Bitcoin hashes and targets

Usage

npm install bitcoin-util

Methods

toHash(hex)

Takes a hex string that contains a Bitcoin hash as input, and returns a Bitcoin-protocol-friendly little-endian Buffer. Throws an error if the hex string is not of length 64 (representing a 256-bit hash).

compressTarget(target)

Converts the difficulty target target to its compact representation (used in the "bits" field in block headers). target should be a Buffer (little-endian, the zeroes should be at the end). Returns a number.

expandTarget(bits)

Converts the compressed target integer bits to its target hash representation. Returns a Buffer.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free