Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cmeone/chia-utils

A set of JavaScript utilities to facilitate conversions for the Chia network
https://github.com/cmeone/chia-utils

bech32 chia chia-blockchain chia-network cryptocurrency cryptography hashing

Last synced: 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

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](#install)
- [Address to Puzzle Hash](#address-to-puzzle-hash)
- [Puzzle Hash to Address](#puzzle-hash-to-address)
- [Get Coin Info](#get-coin-info)
- [Get Coin Info Mojo](#get-coin-info-mojo)
- [Bytes to Hex](#bytes-to-hex)
- [Hex to Bytes](#hex-to-bytes)

## Install
To install from NPM:
```bash
npm install chia-utils
```

To install from GitHub:
```bash
git clone https://github.com/CMEONE/chia-utils.git
```

To test:
```bash
npm install
npm test
```

To include from NPM:
```javascript
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:
```javascript
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:
```html

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( ... )

```

## Address to Puzzle Hash
```javascript
let puzzle_hash = address_to_puzzle_hash(address);
```
**Parameters:**
- address: string ("xch1...")

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

## Puzzle Hash to Address
```javascript
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
```javascript
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
```javascript
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
```javascript
let hex = bytes_to_hex(bytes);
```
**Parameters:**
- bytes: Array or Uint8Array ([0, 255, ...])

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

## Hex to Bytes
```javascript
let bytes = hex_to_bytes(hex);
```
**Parameters:**
- hex: string ("fedcba9876543210...")

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