JavaScript library that decodes, encodes and validates Tezos payment requests.
This package provides a JavaScript implementation of the Tezos URI standard. It is written in ReasonML and compiled to JS.
Currently, when users try to interact with a DApp, they have to copy-paste transaction parameters into their wallet by hand. This interaction is far from frictionless and we've built this package to fix that.
The HTML documentation is here. A step-by-step guide is here.
First install the package from NPM by running the following command:
npm install tezos-uri
Then, you can import it into your project:
ES-style import with a bundler (e.g. webpack)
``js`
import { encodeMainnet, decodeMainnet } from "tezos-uri";
Please note that we don't actually distribute an ES module and this works thanks to the bundler processing your project before deployment. It does not work directly in the browser.
NodeJS require
`js`
const tezosUri = require("tezos-uri");
Simply embed a script tag in your HTML:
`html`
First install the package from NPM by running the following command:
npm install tezos-uri
Then add it to your dependencies in bsconfig.json:
``
{
...
"bs-dependencies": ["tezos-uri"]
}
The project will be available under the TezosUri namespace.
The code is written in ReasonML, a dialect of OCaml, and then compiled to JavaScript. It's easier to read in an editor that supports the language , such as VSCode (using the reason-vscode extension).
You can read the JS files after you build the project, or you can just use the tezosUri-js branch
Validates and encodes a JSON payment request and returns a Tezos URI. Raises an exception on invalid input.
There are some examples of the JSON object in the section below. The exact specification for the payment request JSON is here.
`
/**
* @description Validates and encodes a JSON payment request and returns
* a Tezos Mainnet URI. Raises an exception on invalid input.
* @param {Array
* @returns {string} Tezos Mainnet URI
*/
export declare function encodeMainnet(input: Array
/**
* @description Validates and encodes a JSON payment request and returns
* a Tezos Testnet URI. Raises an exception on invalid input.
* @param {Array
* @returns {string} Tezos Testnet URI
*/
export declare function encodeTestnet(input: Array
`
Decodes and validates a Tezos URI and returns the resulting JSON payment request. Raises an exception when the request is invalid, or when the URI does not match the expected network.
`
/**
* @description Decodes and validates a Tezos URI and returns a resulting
* payment request JSON. Raises an exception when the request is invalid,
* or when the URI is not a Tezos Mainnet URI.
* @param {string} uri Tezos Mainnet URI
* @returns {Array
*/
export declare function decodeMainnet(uri: string): Array
/**
* @description Decodes and validates a Tezos URI and returns a resulting
* payment request JSON. Raises an exception when the request is invalid,
* or when the URI is not a Tezos Testnet URI.
* @param {string} uri Tezos Testnet URI
* @returns {Array
*/
export declare function decodeTestnet(uri: string): Array
`
`js
import { encodeMainnet } from "tezos-uri";
const operation = {
kind: "transaction",
amount: "100000",
destination: "tz1NAP47ubff4JDLJ94UcwEs66dDDAJGRDwN"
};
const link = encodeMainnet([{ content: operation }]);
`
`js
import { decodeMainnet } from "tezos-uri";
const decoded = decodeMainnet(link);
`
Validates and encodes a JSON payment request and returns a Tezos URI. Raises an exception on invalid input.
There are some examples of the JSON object in the section below. The exact specification for the payment request JSON is here.
``
let mainnet: Js.Json.t => string
let testnet: Js.Json.t => string
See the Encode.re file for more details.
Decodes and validates a Tezos URI and returns the resulting JSON payment request. Raises an exception when the request is invalid, or when the URI does not match the expected network.
``
let mainnet: string => Js.Json.t
let testnet: string => Js.Json.t
See the Decode.re file for more details.
`reasonml
let operation = {|
[
{
"content": {
"kind": "transaction",
"amount": "399000",
"destination": "KT1MFdSrM6LqGXaXAWuuXX4tWe8H3n5Xekyg"
}
},
{
"content": {
"kind": "transaction",
"amount": "129000",
"destination": "KT1MFdSrM6LqGXaXAWuuXX4tWe8H3n5Xekyg"
}
}
]
|}
let encodedLink = TezosUri.Encode.testnet(Js.Json.parseExn(operation))
`
`reasonml`
let decodedObject = TezosUri.Decode.testnet(encodedLink)
Get the code and the dependencies:
``
git clone https://gitlab.com/smartcontractlabs/tezos-uri.git
cd tezos-uri
npm install
Then, to build once, run:
``
npm run build
To compile when changes are made, run:
``
npm run start
To make a production ready bundle, run:
``
npm run make:build
The codebase is covered by tests, using the @glennsl/bs-jest bindings for the Jest testing framework. The tests are run with JavaScript files generated by the BuckleScript compiler (not the ReasonML source files).
You can run these tests with npm:
``
npm run test
First, set up the documentation generator and generate stylesheets:
``
npm run bsdoc:init
Then build the HTML:
```
npm run bsdoc:build
MIT
This project is built by Smart Contract Labs and funded by TQ Tezos.