crypto-qr-code
v1.1.0
Published
A library to generate QR codes for cryptocurrency wallet addresses.
Downloads
34
Maintainers
Readme
crypto-qr-code
crypto-qr-code is a library for generating QR codes for cryptocurrency wallet addresses, supporting Bitcoin (BTC) and Ethereum (ETH). It provides options for customizing the QR code's format and currency type.
Installation
You can install crypto-qr-code via npm:
npm install crypto-qr-code
Usage
Here's how to use the library:
import crypto-qr-codeGenerator from 'crypto-qr-code';
const qrGenerator = new crypto-qr-codeGenerator();
async function generateQRCode() {
try {
const qrCodeImage = await qrGenerator.generateQRCode('your_wallet_address', { currency: 'BTC' });
console.log(qrCodeImage); // Outputs the QR code as a base64-encoded image
} catch (error) {
console.error(error);
}
}
generateQRCode();
Options
The generateQRCode
method accepts two parameters:
- address: The wallet address for the cryptocurrency (required).
- options: An object that can include:
- currency: The type of cryptocurrency (default:
BTC
). Options areBTC
for Bitcoin andETH
for Ethereum. - format: The desired image format for the QR code (default:
image/png
). Options areimage/png
,image/jpeg
, andimage/svg+xml
.
- currency: The type of cryptocurrency (default:
Error Scenarios
- Empty Wallet Address: The wallet address is a required parameter.
- Invalid Currency: At present, we support only BTC and ETH.
- Invalid Wallet Address: If the provided address is not according to the standards, an error will be thrown.
- QR Code Generation Error: If there is problem generating the QR code, an error will be thrown.
Examples
- Here’s a full example of generating a QR code for a Bitcoin address:
const qrCodeImage = await qrGenerator.generateQRCode('your_btc_wallet_address', { currency: 'BTC', format: 'image/png' });
console.log(qrCodeImage); // Base64 encoded PNG image
- Here’s a full example of generating a QR code for a Ethereum address:
const qrCodeImageETH = await qrGenerator.generateQRCode('your_eth_wallet_address', { currency: 'ETH', format: 'image/jpeg' });
console.log(qrCodeImageETH); // Base64 encoded JPEG image
License
This project is licensed under the MIT License - see the LICENSE file for details.