NEM2 QR Library generator to generate QR codes for Catapult (NEM2) accounts and transactions.
This is a PoC to validate the proposed NIP 7 QR Library Standard Definition. When stable, the repository will be moved to the nemtech organization.
npm install nem2-qr-library
import { QRCodeGenerator } from 'nem2-qr-library';
// (Optional) create transfer transaction (or read from network)
const transfer = TransferTransaction.create(
Deadline.create(),
Address.createFromPublicKey(
'C5C55181284607954E56CD46DE85F4F3EF4CC713CC2B95000FA741998558D268',
NetworkType.MIJIN_TEST
),
[new Mosaic(new NamespaceId('cat.currency'), UInt64.fromUint(10000000))],
PlainMessage.create('Welcome to NEM!'),
NetworkType.MIJIN_TEST
);
// create QR Code base64
const request = QRCodeGenerator.createTransactionRequest(transfer);
// get base64 notation for <img> HTML attribute
const base64 = request.toBase64();
import { QRCodeGenerator } from 'nem2-qr-library';
// define custom object to suit your application use case.
const object = {"obj": "test"};
// create QR Code base64
const request = QRCodeGenerator.createExportObject(object, NetworkType.TEST_NET);
// get base64 notation for <img> HTML attribute
const base64 = request.toBase64();
import {
PublicAccount,
NetworkType,
} from 'nem2-sdk';
const name = 'test-contact-1';
const account = PublicAccount.createFromPublicKey(
'C5C55181284607954E56CD46DE85F4F3EF4CC713CC2B95000FA741998558D268',
NetworkType.TEST_NET
);
// create QR Code base64
const request = QRCodeGenerator.createAddContact(name, account);
// get base64 notation for <img> HTML attribute
const base64 = request.toBase64();
import {
Account,
NetworkType,
Password,
} from 'nem2-sdk';
import { MnemonicPassPhrase } from 'nem2-hd-wallets';
// create a mnemonic and password.
const mnemonic = MnemonicPassPhrase.createRandom();
const password = new Password('password');
// create QR Code base64
const exportMnemonic = new MnemonicQR(mnemonic, password, NetworkType.MIJIN_TEST, 'no-chain-id');
// get base64 notation for <img> HTML attribute
const base64 = exportMnemonic.toBase64();
The produced Base64 encoded payload can be used to display the QR Code. An example of display can be done easily with HTML, as follows:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Transfer Transaction QR code" />
Important versions listed below. Refer to the Changelog for a full history of the project.
Licensed under the Apache License, Version 2.