# bitcoin-transaction

> Send BitCoins from one wallet to another. This is designed to be as simple to use as possible.

Latest version **1.2.1** (published 2018-11-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install bitcoin-transaction
pnpm add bitcoin-transaction
yarn add bitcoin-transaction
bun add bitcoin-transaction
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2018-11-02 |
| First published | 2017-11-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 19.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 53 |
| Author | Sam MacPherson |
| Maintainers | blank101 |
| Keywords | bitcoin, transaction, wallet |

## Links

- npm: https://www.npmjs.com/package/bitcoin-transaction
- Repository: https://github.com/Blank101/bitcoin-transaction
- Homepage: https://github.com/Blank101/bitcoin-transaction#readme
- Issues: https://github.com/Blank101/bitcoin-transaction/issues
- npm.io page: https://npm.io/package/bitcoin-transaction

## Dependencies (2)

- [superagent](https://npm.io/package/superagent.md) ^3.8.0
- [bitcoinjs-lib](https://npm.io/package/bitcoinjs-lib.md) ^3.3.0

## Recent versions

- 1.2.1 (latest) — 2018-11-02
- 1.1.1 — 2018-07-10
- 1.1.0 — 2017-11-23
- 1.0.0 — 2017-11-03

## README

# bitcoin-transaction

The simpliest way to send bitcoins from one wallet to another using javascript. This library will hook into popular third party services such as blockchain.info and blockexplorer.com to do all the heavy lifting in sending a bitcoin transaction. Other libraries require you to parse 3rd party apis or run external software to send a transaction. This library is meant to be as simple as possible while still allowing for customization.

Designed to run on both NodeJS and in the browser.

## Installation

	npm install --save bitcoin-transaction

or for the browser

	npm install -g browserify uglify-js
	npm install bitcoin-transaction
	browserify -r bitcoin-transaction -s bitcoinTransaction | uglifyjs > bitcoin-transaction.min.js

## Usage

	var bitcoinTransaction = require('bitcoin-transaction');

	//Send all my money from wallet1 to wallet2 on the bitcoin testnet
	var from = "mm3gdVh8n6YtcNyaTKYkveB6yTME7aDWNJ";
	var to = "mgPUfqJk4X6gE4P5Do5RfpkTFsYmsSjCya";
	var privKeyWIF = "cNZi8iySqBToXMpcsQaHKD5uv7HExBQJBSi4dTg3ZPaEzeNAzvbj";	//Private key in WIF form (Can generate this from bitcoinlib-js)

	bitcoinTransaction.getBalance(from, { network: "testnet" }).then((balanceInBTC) => {
		return bitcoinTransaction.sendTransaction({
			from: from,
			to: to,
			privKeyWIF: privKeyWIF,
			btc: balanceInBTC,
			network: "testnet"
		});
	});

## API

### bitcoinTransaction.providers

**Advanced**

Contains the services that provide low level functionality on the blockchain. Sensible defaults are set out of the box, but feel free to adjust these as you see fit. There are 4 provider types:

 * balance - Retrieves the balance of a wallet.
 * fees - Gets a list of current fees based on the BitCoin network going rate.
 * utxo - Pull a list of unspent transaction outputs.
 * pushtx - Push a raw transaction onto the blockchain.

Feel free to change the defaults by setting the default property on the provider. For example:

	//Set the default main network balance provider to blockchain.info instead of blockexplorer.com
	bitcoinTransaction.providers.balance.mainnet.default = bitcoinTransaction.providers.balance.mainnet.blockchain;

### bitcoinTransaction.getBalance(address, options)

Returns a promise that yields the balance of the given address.

Option | Default | Description
--- | --- | ---
**network** | "mainnet" | Set the BitCoin network. Either "mainnet" or "testnet".
**balanceProvider** | providers.balance[NETWORK].default | Set the service provider to fetch the balance.

### bitcoinTransaction.sendTransaction(options)

Returns a promise that pushes a live transaction on the BitCoin blockchain.

Option | Default | Description
--- | --- | ---
**from** (Required) | N/A | The wallet where you are getting the funds from.
**to** (Required) | N/A | The wallet where you are sending the funds to.
**privKeyWIF** (Required) | N/A | The private key for the `from` wallet.
**btc** (Required) | N/A | The amount to send in BitCoin (BTC).
**network** | "mainnet" | Set the BitCoin network. Either "mainnet" or "testnet".
**fee** | "fastest" | Set the fee for the transaction. Can be either one of "fastest", "halfHour" or "hour" in which case the actual fee numbers are fetched from the `fees` provider. Or it can be just a plain number in which case that will be used as the Fee per Byte value in Satoshis. It is recommended to use one of the string aliases unless you know what you are doing.
**feesProvider** | providers.fees[NETWORK].default | Set the service provider to fetch the fees.
**utxoProvider** | providers.utxo[NETWORK].default | Set the service provider to fetch the utxos.
**pushtxProvider** | providers.pushtx[NETWORK].default | Set the service provider to push the transaction raw hex code.
**dryrun** | false | This will not push the transaction, but instead return it as a hex string. Useful for debugging.
**minConfirmations** | 6 | The minimum number of confirmations needed for UTXOs

---
_Source: https://npm.io/package/bitcoin-transaction · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
