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

web3-qr-code

v1.0.0

Published

This is an npm package that provides functions to generate QR codes for multi blockchain like Ethereum, Bitcoin, and Solana cryptocurrencies.

Downloads

5

Readme

Web3 QR Code

This is an npm package that provides functions to generate QR codes for multi blockchain like Ethereum, Bitcoin, and Solana cryptocurrencies.

Installation

Install the package using npm:

npm install web3-qr-code

Usage

Import the package and create an instance of the QrCode class:

import { QrCode } from 'qr-code-generator';
const qrCode = new QrCode();

Generate Ethereum QR Code

  1. Generate an Ethereum QR code for transfer of eth by calling the generateETHqrCode method with the required parameters:
const params = {
  from: 'sender-address',
  to: 'recipient-address',
  value: 0.5,
  chainId: 1
};

const qrCodeDataURL = await qrCode.generateETHqrCode(params);
console.log(qrCodeDataURL);
  1. Generate an Ethereum QR code for smart contract transaction by calling the generateETHqrCode method with the required parameters:
const params = {
  from: '0xF9d3C2Adc0dA3B68621fCcFA7c51B66eAf000a05',
  to: '0xdac17f958d2ee523a2206206994597c13d831ec7', // contract address
  value: 0,
  chainId: 1,
  functionName: 'transfer', // smart contract method
  functionArgs: [
    { name: 'to', type: 'address', value: '0xF9d3C2Adc0dA3B68621fCcFA7c51B66eAf000f0c' },
    { name: 'amount', type: 'uint256', value: 1000 },
  ],
};

const qrCodeDataURL = await qrCode.generateETHqrCode(params);
console.log(qrCodeDataURL);

Generate Bitcoin QR Code

Generate a Bitcoin QR code by calling the generateBTCqrCode method with the required parameters:

const params = {
  to: 'bitcoin-address',
  amount: 0.001,
  label: 'Payment for goods',
  message: 'Optional message',
  extra: [
    { key: 'param1', value: 'value1' },
    { key: 'param2', value: 12345 },
  ],
};

const qrCodeDataURL = await qrCode.generateBTCqrCode(params);
console.log(qrCodeDataURL);

Generate Solana QR Code

  1. Generate a Solana QR code for transfer of sol by calling the generateSOLqrCode method with the required parameters:
const params = {
  to: 'solana-address',
  amount: 1.234,
  label: 'Payment for services',
  memo: 'Optional memo',
  feePayer: 'fee-payer-address'
};

const qrCodeDataURL = await qrCode.generateSOLqrCode(params);
console.log(qrCodeDataURL);
  1. Generate a Solana QR code for smart contract method transaction by calling the generateSOLqrCode method with the required parameters:
const params = {
  to: 'solana-address',
  amount: 1.234,
  label: 'Payment for services',
  memo: 'Optional memo',
  delegate: 'delegate-address',
  authorized: 'authorized-address',
  programId: 'program-id',
  methodName: 'method-name',
  args: { arg1: 'value1', arg2: 12345 },
  feePayer: 'fee-payer-address',
  referral: 'referral-address',
};

const qrCodeDataURL = await qrCode.generateSOLqrCode(params);
console.log(qrCodeDataURL);

Interfaces

IFuncArgs

Represents an Ethereum contract function argument.

  • name (string): The name of the argument.
  • type (string): The type of the argument.
  • value (string or number): The value of the argument.

IETHqrCode

Represents the parameters for generating an Ethereum QR code.

  • from (string, optional): The sender address.
  • to (string): The recipient address.
  • value (number, optional): The value to be sent (in ETH).
  • chainId (number, optional): The Ethereum chain ID.
  • functionName (string, optional): The name of the contract function.
  • functionArgs (IFuncArgs[], optional): The arguments for the contract function.

IExtra

Represents an extra parameter for Bitcoin QR code.

  • key (string): The key of the parameter.
  • value (string or number): The value of the parameter.

IBTCqrCode

Represents the parameters for generating a Bitcoin QR code.

  • to (string): The recipient address.
  • amount (number, optional): The amount to be sent (in BTC).
  • label (string, optional): A label for the transaction.
  • message (string, optional): An optional message.
  • extra (IExtra[], optional): Extra parameters for the QR code.

ISOLqrCode

Represents the parameters for generating a Solana QR code.

  • to (string): The recipient address.
  • amount (number, optional): The amount to be sent (in SOL).
  • label (string, optional): A label for the transaction.
  • memo (string, optional): An optional memo.
  • delegate (string, optional): The delegate address.
  • authorized (string, optional): The authorized address.
  • programId (string, optional): The program ID.
  • methodName (string, optional): The method name.
  • args (any, optional): Additional arguments for the method.
  • feePayer (string, optional): The fee payer address.
  • referral (string, optional): The referral address.