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

@crpdo/coins

v0.0.3

Published

A host of methods to manage a variety of cryptocurrencies, such as deriving paths for coin symbols, obtaining coin type IDs, and generating Bitcoin or Ethereum addresses for specific public keys.

Downloads

23

Readme

@crpdo/coins

Cha Ching

npm pipeline license downloads

Gitlab Twitter Discord

Coins is a utility class containing methods for working with different types of cryptocurrencies as part of the crpdo project. This module is particularly helpful for tasks like getting coin type IDs, deriving paths for a coin symbol, and getting Bitcoin or Ethereum addresses for given public keys, among other tasks.

Installation

npm install @crpdo/coins

Usage

Below are some examples of how to use the Coins module:

const Coins = require('@crpdo/coins')

const coinTypeId = Coins.getCoinType('BTC')  // Get coin type id for Bitcoin
console.log(coinTypeId)  // Outputs: 0

const derivePath = Coins.getDerivePath('ETH', 0, 0)  // Get derive path for Ethereum
console.log(derivePath)  // Outputs: "m/44'/60'/0'/0"

const btcAddress = Coins.getBtcAddress('somePublicKey', 'bitcoin')  // Get Bitcoin address for a given public key
console.log(btcAddress)  // Outputs: the Bitcoin address

const isValidAddress = Coins.validateAddress('BTC', 'someAddress')  // Validate a given address for Bitcoin
console.log(isValidAddress)  // Outputs: true or false depending on the address

const coinInfo = Coins.getCoinInfo('ETH')  // Get comprehensive information for Ethereum
console.log(coinInfo)  // Outputs: the information for Ethereum

const transactionFee = await Coins.getTransactionFee('BTC')  // Get the current average transaction fee for Bitcoin
console.log(transactionFee)  // Outputs: the current average transaction fee for Bitcoin

const convertedAmount = await Coins.convertAmount('BTC', 1, 'ETH')  // Convert 1 Bitcoin to Ethereum
console.log(convertedAmount)  // Outputs: the equivalent amount in Ethereum

Please note that in order to use the getTransactionFee and convertAmount methods, you need to use the await keyword because they are asynchronous.

Documentation

API

Coins.getCoinType(coinSymbol)

Get the coin type id for a given coin symbol.

Parameters:

  • coinSymbol - String: The symbol for the coin e.g. 'BTC'.

Returns:

  • Number: The coin type id for the coin symbol.

Coins.getDerivePath(coinSymbol, account, change, index)

Get the derive path for a coin symbol, account, change, and optionally index.

Parameters:

  • coinSymbol - String: The symbol for the coin. Default: 'BTC'.
  • account - Number: The account number. Default: 0.
  • change - Number: The change number. Default: 0.
  • index - Number: The index number. Optional.

Returns:

  • String: The derive path.

Coins.getNetwork(coinSymbol)

Set up network parameters for Dogecoin. This method currently only supports 'DOGE'.

Parameters:

  • coinSymbol - String: The symbol for the coin e.g. 'DOGE'.

Coins.getBtcAddress(pubkey, network)

Get a Bitcoin address for a given public key.

Parameters:

  • pubkey - String|Buffer: The public key as a string or buffer.
  • network - String: The network name. Default: 'bitcoin'.

Returns:

  • String: The Bitcoin address.

Coins.getEthAddress(pubkey)

Get an Ethereum address for a given public key.

Parameters:

  • pubkey - String|Buffer: The public key as a string or buffer.

Returns:

  • String: The Ethereum address.

Coins.getCoinName(coinSymbol)

Get the full name of a given coin.

Parameters:

  • coinSymbol - String: The symbol for the coin e.g. 'BTC'.

Returns:

  • String: The full name of the coin.
  • Throws an error if the coin symbol is not supported.

Coins.validateAddress(coinSymbol, address)

Validate a given address for a specific coin type.

Parameters:

  • coinSymbol - String: The symbol for the coin e.g. 'BTC'.
  • address - String: The address to validate.

Returns:

  • Boolean: True if the address is valid, false otherwise.
  • Throws an error if the coin symbol is not supported.

Coins.getCoinInfo(coinSymbol)

Get a comprehensive set of information for a specific coin.

Parameters:

  • coinSymbol - String: The symbol for the coin e.g. 'BTC'.

Returns:

  • Object: An object containing the coin information.
  • Throws an error if the coin symbol is not supported.

Coins.getTransactionFee(coinSymbol)

Get the current average transaction fee for a given coin.

Parameters:

  • coinSymbol - String: The symbol for the coin e.g. 'BTC'.

Returns:

  • Number: The current average transaction fee.
  • Throws an error if the coin symbol is not supported.

Coins.convertAmount(coinSymbol, amount, toCoinSymbol)

Convert an amount of one cryptocurrency to another.

Parameters:

  • coinSymbol - String: The symbol for the source coin.
  • amount - Number: The amount of the source coin to convert.
  • toCoinSymbol - String: The symbol for the target coin.

Returns:

  • Number: The equivalent amount in the target coin.
  • Throws an error if either coin symbol is not supported.

Tests

In order to run the test suite, simply clone the repository and install its dependencies:

git clone https://gitlab.com/frenware/core/crpdo/coins.git
cd basd
npm install

To run the tests:

npm test

Contributing

Thank you! Please see our contributing guidelines for details.

Donations

If you find this project useful and want to help support further development, please send us some coin. We greatly appreciate any and all contributions. Thank you!

Bitcoin (BTC):

1JUb1yNFH6wjGekRUW6Dfgyg4J4h6wKKdF

Monero (XMR):

46uV2fMZT3EWkBrGUgszJCcbqFqEvqrB4bZBJwsbx7yA8e2WBakXzJSUK8aqT4GoqERzbg4oKT2SiPeCgjzVH6VpSQ5y7KQ

License

@crpdo/coins is MIT licensed.