Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/dawsbot/satoshi-bitcoin
- Owner: dawsbot
- License: mit
- Created: 2015-07-23T03:13:14.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-05-20T05:48:30.000Z (6 months ago)
- Last Synced: 2024-10-29T05:20:52.490Z (12 days ago)
- Topics: bitcoin, crypto, satoshi
- Language: JavaScript
- Homepage:
- Size: 108 KB
- Stars: 42
- Watchers: 4
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-wallet - satoshi-bitcoin
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);
//=>100000000sb.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)