Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

satoshi-bitcoin

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

satoshi-bitcoin

Convert Satoshi <-> Bitcoin

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.4K
increased by10.75%
Maintainers
1
Weekly downloads
 
Created
Source

satoshi-bitcoin

Build Status npm version

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


The Problem

The problem


Install

npm install --save satoshi-bitcoin

# OR

yarn add satoshi-bitcoin

Usage

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

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

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

Web
<!-- package injected as "sb" -->
<script src="https://rawgit.com/dawsonbotsford/satoshi-bitcoin/master/index.bundle.js"></script>
<script>
  console.log("One Satoshi equals " + sb.toBitcoin(1) + " Bitcoin");
</script>

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

<script src="node_modules/satoshi-bitcoin/index.bundle.js"></script>

Error Handling

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


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 - Floating point errors are a problem. So satoshi-bitcoin uses a tiny bignum library (big.js) to ensure accurate conversions!

Tests

npm test

License

MIT © Dawson Botsford

Keywords

FAQs

Package last updated on 30 May 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc