Socket
Socket
Sign inDemoInstall

@glif/filecoin-number

Package Overview
Dependencies
Maintainers
3
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@glif/filecoin-number

a javascript package to handle Filecoin numbers like Fil and AttoFil


Version published
Weekly downloads
552
decreased by-22.69%
Maintainers
3
Weekly downloads
 
Created
Source

Filecoin number

A wrapper class built around javascript's bignumber. Most questions are best answered from the bignumber readme and docs.

FilecoinNumber Usage

import { FilecoinNumber, Converter } from '@glif/filecoin-number'

// pass a valid bignumber argument, and a denomination ('fil', 'picofil', or 'attofil') to the constructor.
const filecoinNumber = new FilecoinNumber('10000', 'attofil')

// filecoinNumber is an instance of BigNumber, so you can use it as such
filecoinNumber.multiply(7)

// it comes with 2 additional instance methods for showing the filecoin number as a string in attofil or fil
const inPicoFil = filecoinNumber.toPicoFil()
const inAttoFil = filecoinNumber.toAttoFil()
const inFil = filecoinNumber.toFil()

Converter Usage

// Use the Converter to convert currencies
const optionalConfig = {
  apiURL: 'https://coinmarketproxy.com',
  apiKey: 'RIP Kobe',
}

const USDConverter = new Converter('USD', optionalConfig)

await USDConverter.cacheConversionRate()

const USD = USDConverter.fromFIL(1)
const FIL = USDConverter.toFIL(1)

// fromFIL and toFIL take numbers, strings, BigNumbers, and FilecoinNumbers as valid args
const USD = USDConverter.fromFIL(1)
const USD = USDConverter.fromFIL('1')
const USD = USDConverter.fromFIL(new BigNumber(1))
const USD = USDConverter.fromFIL(new FilecoinNumber('1', 'fil'))

Running tests locally

We use an APIADDR environment variable in the tests. You can either: (a) add the APIADDR environment variable locally, or (b) use a secrets.js file to export private information

FAQs

Package last updated on 28 Mar 2023

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