A set of JavaScript utilities to facilitate conversions for the Chia network
- Install
- Address to Puzzle Hash
- Puzzle Hash to Address
- Get Coin Info
- Get Coin Info Mojo
- Bytes to Hex
- Hex to Bytes
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>
let puzzle_hash = address_to_puzzle_hash(address);
Parameters:
- address: string ("xch1...")
Return type: string ("0x...")
let address = puzzle_hash_to_address(puzzle_hash, prefix = "xch");
Parameters:
- puzzle_hash: string ("0x...")
- prefix: string ("xch") - default: "xch"
Return type: string ("xch1...")
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...")
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...")
let hex = bytes_to_hex(bytes);
Parameters:
- bytes: Array or Uint8Array ([0, 255, ...])
Return type: string ("fedcba9876543210...")
let bytes = hex_to_bytes(hex);
Parameters:
- hex: string ("fedcba9876543210...")
Return type: Uint8Array ([0, 255, ...])