gc-encoder
v1.0.4
Published
Gamechanger url encoder
Downloads
5
Maintainers
Readme
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
});