npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

conversao-crypto-rodrigo

v1.3.1

Published

You can basically use this library for two things: - Check the quote on any crypto currency in the world, this basic quote is given to you in USD (United States Dollar).

Downloads

5

Readme

Using the library

You can basically use this library for two things:

  • Check the quote on any crypto currency in the world, this basic quote is given to you in USD (United States Dollar).

  • Convert one specific crypto currency into one, or many others.

Installing the library

To install the library, all you have to do is run the following shell command in the root of your project:

npm install conversao-crypto-rodrigo

Importing it into your project

Just like any other lib, you must import it into your project in order to use it, we do it as follows:

const cryptoConversor = require('conversa-crypto-rodrigo');

Just so we are clear, you can give it any name when you import it, cryptoConversor was just an example.

Getting a currency's quote in USD

Now that you've installed and imported the lib into your project, you can use the quote method giving it all the symbols of the currencies you wanna quote. In the example below, I wanna quote the values of 1 bitcoin e 1 etherium, in USD:

const currenciesQuotes = cryptoConversor.quote(['BTC', 'ETH']) 

Running this, just like that, might give you the following error:

{ error: 'BTC was not found or missing SECRET_API_KEY on .env file'}

If you get this error, it prabibly means you haven't added your secret API key to a .env file. So go ahead and create a .env file. Inside it, you should have the value of your secret API key, which can be obtained here.

Once you have created an account and/or logged in, you should be able to have access to the key, now all you have to do is add to the file like this:

SECRET_API_KEY="YOUR_SECRET_KEY"

It is safer if you put all of your key in between quotes. Done, all yout major configuration is now good to go! A successfull response for the lib, should look like this:

[
    {
      id: 1,
      name: 'Bitcoin',
      symbol: 'BTC',
      slug: 'bitcoin',
      date_added: '2013-04-28T00:00:00.000Z',
      last_updated: '2022-02-15T09:34:00.000Z',
      quotes: [Object]
    },
    {
      id: 1027,
      name: 'Ethereum',
      symbol: 'ETH',
      slug: 'ethereum',
      date_added: '2015-08-07T00:00:00.000Z',
      last_updated: '2022-02-15T09:34:00.000Z',
      quotes: [Object]
    }
]

The quotes object contains all the information regarding the USD values of that crypto.

Note

This lib relies on an API request, so it should be use in an async function, otherwise you will receive only promises and not the real results!

Converting one crypto into one or many others

For that, all you have to do is use the conversion method in the cryptoConversor object. You must give it the origin crypto's symbol, the amount you want to convert, and an array with all the cryptos you want it to the be converted to.

So lets assume I want to figure out how much Etherium and Tether are 3 bitcoins worth, I would use the method like this:

const currenciesConversion = cryptoConversor.conversion('BTC', 3, ['ETH','USDT']);

The successfull result should look like this:

{
    id: 1,
    symbol: 'BTC',
    name: 'Bitcoin',
    amount: 3,
    last_updated: '2022-02-15T09:59:00.000Z',
    quotes: [ [Object], [Object] ]
  }

In the quotes key of the response we have the two objects with the corresponding conversions.

Note:

You must keep in mind that both methods require an SECRET_API_KEY in the .env file (as mentioned before), and both methods have asynchronous responses, so you shoud use async and await.