chia-utils

A set of JavaScript utilities to facilitate conversions for the Chia network


Keywords
hashing, cryptography, cryptocurrency, bech32, chia, chia-blockchain, chia-network
License
Other
Install
npm install chia-utils@1.0.10

Documentation

Unofficial Library: Chia-Utils

Build Status Version Version Monthly Downloads Total Downloads

A set of JavaScript utilities to facilitate conversions for the Chia network

Table of Contents

Install

To install from NPM:

npm install chia-utils

To install from GitHub:

git clone https://github.com/CMEONE/chia-utils.git

To test:

npm install
npm test

To include from NPM:

const { address_to_puzzle_hash, puzzle_hash_to_address, get_coin_info, get_coin_info_mojo, bytes_to_hex, hex_to_bytes } = require("chia-utils");

To include from file:

const { address_to_puzzle_hash, puzzle_hash_to_address, get_coin_info, get_coin_info_mojo, bytes_to_hex, hex_to_bytes } = require("./chia-utils.js");

To use in the browser:

<script type="text/javascript" src="chia-utils.js"></script>
<script>
  ChiaUtils.address_to_puzzle_hash( ... )
  ChiaUtils.puzzle_hash_to_address( ... )
  ChiaUtils.get_coin_info( ... )
  ChiaUtils.get_coin_info_mojo( ... )
  ChiaUtils.bytes_to_hex( ... )
  ChiaUtils.hex_to_bytes( ... )
</script>

Address to Puzzle Hash

let puzzle_hash = address_to_puzzle_hash(address);

Parameters:

  • address: string ("xch1...")

Return type: string ("0x...")

Puzzle Hash to Address

let address = puzzle_hash_to_address(puzzle_hash, prefix = "xch");

Parameters:

  • puzzle_hash: string ("0x...")
  • prefix: string ("xch") - default: "xch"

Return type: string ("xch1...")

Get Coin Info

let coin_info = get_coin_info(parent_coin_info, puzzle_hash, amount_decimal);

Parameters:

  • parent_coin_info: string ("0x...")
  • puzzle_hash: string ("0x...")
  • amount_decimal: number (0.01)

Return type: string ("0x...")

Get Coin Info Mojo

let coin_info = get_coin_info_mojo(parent_coin_info, puzzle_hash, amount);

Parameters:

  • parent_coin_info: string ("0x...")
  • puzzle_hash: string ("0x...")
  • amount: number (1000000000000)

Return type: string ("0x...")

Bytes to Hex

let hex = bytes_to_hex(bytes);

Parameters:

  • bytes: Array or Uint8Array ([0, 255, ...])

Return type: string ("fedcba9876543210...")

Hex to Bytes

let bytes = hex_to_bytes(hex);

Parameters:

  • hex: string ("fedcba9876543210...")

Return type: Uint8Array ([0, 255, ...])