New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

crypto-qr-code

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crypto-qr-code

A library to generate QR codes for cryptocurrency wallet addresses.

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
0
Created
Source

crypto-qr-code

crypto-qr-code License

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

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 are BTC for Bitcoin and ETH for Ethereum.
    • format: The desired image format for the QR code (default: image/png). Options are image/png, image/jpeg, and image/svg+xml.

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.

Keywords

qrcode

FAQs

Package last updated on 04 Oct 2024

Did you know?

Socket

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.

Install

Related posts