Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dawsbot/satoshi-bitcoin

Convert precisely between Satoshi and Bitcoin
https://github.com/dawsbot/satoshi-bitcoin

bitcoin crypto satoshi

Last synced: 3 days ago
JSON representation

Convert precisely between Satoshi and Bitcoin

Awesome Lists containing this project

README

        

# satoshi-bitcoin

![](https://badgen.net/bundlephobia/min/satoshi-bitcoin)
[![๐Ÿงช npm test](https://github.com/dawsbot/satoshi-bitcoin/actions/workflows/test.yml/badge.svg)](https://github.com/dawsbot/satoshi-bitcoin/actions/workflows/test.yml)
[![npm version](https://badge.fury.io/js/satoshi-bitcoin.svg)](http://badge.fury.io/js/satoshi-bitcoin)

> npm module to convert between Satoshi and Bitcoin with lightweight precision.


## The Problem

![The problem](http://i.imgur.com/H1Ck3bF.png)


## Install

```bash
npm install --save satoshi-bitcoin

# OR

yarn add satoshi-bitcoin
```


## Usage

#### Node.js

```js
var sb = require("satoshi-bitcoin");

sb.toSatoshi(1);
//=>100000000

sb.toBitcoin(100000000);
//=>1
```


#### Web

```html

console.log("One Satoshi equals " + sb.toBitcoin(1) + " Bitcoin");

```


Or download it with `npm install --save satoshi-bitcoin` and reference it as:

```html

```


### Error Handling

```javascript
try {
sb.toSatoshi(false); //Throws TypeError
} catch (err) {
console.log(err);
}
```


## API

`sb.toSatoshi(number || string)`
`sb.toBitcoin(number || string)`

[Read more on the Wiki](https://github.com/dawsonbotsford/satoshi-bitcoin/blob/master/wiki/index.md)


## FAQ

- What is a Satoshi?

- Satoshi is to Bitcoin as pennies are to the dollar. Except that there are 100,000,000 Satoshi in one Bitcoin.

- Why do I need a module when I can just divide or multiply by 100,000,000?
- [See here](http://repl.it/zlF/4) - Floating point errors are a problem. So `satoshi-bitcoin` uses a tiny bignum library (big.js) to ensure accurate conversions!


## Tests

```bash
npm test
```


## License

MIT ยฉ [Dawson Botsford](https://dawsbot.com)