https://github.com/miguelo981/crypto-price-converter
Easy-to-use lib for converting cryptocurrency prices
https://github.com/miguelo981/crypto-price-converter
bitcoin cryptocurrency ethereum nodejs web3
Last synced: 3 months ago
JSON representation
Easy-to-use lib for converting cryptocurrency prices
- Host: GitHub
- URL: https://github.com/miguelo981/crypto-price-converter
- Owner: Miguelo981
- License: mit
- Created: 2024-01-01T17:54:30.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-01T19:11:21.000Z (over 1 year ago)
- Last Synced: 2025-03-01T22:05:51.603Z (4 months ago)
- Topics: bitcoin, cryptocurrency, ethereum, nodejs, web3
- Language: TypeScript
- Homepage:
- Size: 28.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Crypto Price Converter Library
The Crypto Price Converter library allows developers to easily convert between cryptocurrency and traditional currency values. It leverages the CryptoConverter API for accurate and up-to-date conversion rates.
## Installation
```bash
npm install crypto-price-converter
```## Usage
Initialize the library with your CryptoConverter API:
```javascript
const { CryptoConverterAPI } = require("crypto-price-converter");const converter = new CryptoConverterAPI();
```### Convert token quantity to currency
```javascript
const { CryptoConverterAPI } = require("crypto-price-converter");const converter = new CryptoConverterAPI()
converter.ConvertToCrypto({ symbol: "Bitcoin", amount: 1, currency: "USD" })
```
Output:
```javascript
{ amount: 43149, currency: 'USD', symbol: 'Bitcoin' }
```### Convert your currency amount to crypto value
```javascript
const { CryptoConverterAPI } = require("crypto-price-converter");const converter = new CryptoConverterAPI()
converter.ConvertToCurrency({ symbol: "Bitcoin", amount: 1, currency: "USD" })
```
Output:
```javascript
{ amount: 0.0000231755081230156, currency: 'USD', symbol: 'Bitcoin' }
```### CommonJs and ESModules Support
```javascript
const { CryptoConverterAPI } = require("crypto-price-converter");
``````javascript
import { CryptoConverterAPI } from "crypto-price-converter"
```### Error handling
API requests can potentially return errors due to invalid inputs or other issues. These errors can be handled with a `try...catch` statement, and the error details can be found in either `error.response` or `error.message`: