Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
@crpdo/coins
Advanced tools
Readme
Cha Ching
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.
npm install @crpdo/coins
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.
Get the coin type id for a given coin symbol.
Parameters:
coinSymbol
- String: The symbol for the coin e.g. 'BTC'.Returns:
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:
Set up network parameters for Dogecoin. This method currently only supports 'DOGE'.
Parameters:
coinSymbol
- String: The symbol for the coin e.g. 'DOGE'.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:
Get an Ethereum address for a given public key.
Parameters:
pubkey
- String|Buffer: The public key as a string or buffer.Returns:
Get the full name of a given coin.
Parameters:
coinSymbol
- String: The symbol for the coin e.g. 'BTC'.Returns:
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:
Get a comprehensive set of information for a specific coin.
Parameters:
coinSymbol
- String: The symbol for the coin e.g. 'BTC'.Returns:
Get the current average transaction fee for a given coin.
Parameters:
coinSymbol
- String: The symbol for the coin e.g. 'BTC'.Returns:
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:
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
Thank you! Please see our contributing guidelines for details.
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
@crpdo/coins is MIT licensed.
FAQs
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.
We found that @crpdo/coins demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.