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.
You can install crypto-qr-code via npm:
npm install crypto-qr-code
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();
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:
- 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.
- 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
This project is licensed under the MIT License - see the LICENSE file for details.