1.0.4 • Published 11 months ago

gc-encoder v1.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

gc-encoder

This package allows you to encode and decode json into url safe strings. With this you can give the gamechanger wallet commands.

Example usage

import { gc_encode, gc_encode_qrcode_svg } from "gc-encoder"
import fs from 'fs';

// Go to the gamechanger.finance website. When you have a wallet you can
// navigate to the playground. There are plenty of examples there for
// transactions scripts. 
let json_data = `{
    "type": "script",
    "title": "Minimal Coin Sending Demo",
    "description": "GC Payment",
    "run": [
        {
            "type": "buildTx",
            "tx": {
                "outputs": [
                    {
                        "address": "addr_test1qrl07u9ssdtdwtzhrt0zrrr79yejxhfvmsmjt9jxqyaz0ktp6ydulqht6r9z4ld0jms3a3c7gw45u32vhc2ftdp2f6rqvz02jw",
                        "assets": [
                            {
                                "policyId": "ada",
                                "assetName": "ada",
                                "quantity": "1000000"
                            }
                        ]
                    }
                ]
            }
        },
        {
            "type": "signTxs",
            "detailedPermissions": false,
            "txs": [
                "{get('cache.0.txHex')}"
            ]
        },
        {
            "type": "submitTxs",
            "txs": "{get('cache.1')}"
        }
    ]
}`;

//console.log(json_data);

// Create a complete link for running a transaction. 
// This is built for v2 of Gamechanger. So only beta network is available
let gc_url = gc_encode_complete(json_data, "beta-preprod")
console.log(gc_url);

// Or create a QR code of the link for easy scanning with smartphones. 
// Returns a SVG as a string.
let qr_svg = await gc_encode_qrcode_svg(json_data,"beta-preprod");
//console.log(qr_svg);

// You can write the QR code to a file or directly use it in your application
fs.writeFile('./test.svg', qr_svg, err => {
  if (err) {
    console.error(err);
  }
  // file written successfully
});
1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago