Socket
Socket
Sign inDemoInstall

@glif/filecoin-number

Package Overview
Dependencies
3
Maintainers
0
Versions
52
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@glif/filecoin-number


Version published
Maintainers
0
Install size
765 kB
Created

Readme

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

Last updated on 26 Jun 2024

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc