GreenWeb.js#

Chia JavaScript API

About#

GreenWeb.js is a JavaScript library that allows writing web-based apps that interact with the Chia blockchain. The source code can be found on GitHub.

General Structure#

The main javascript files exports a single object, greenweb. It has the following sub-modules:

The object also exports the following classes as properties:

  • SmartCoin: GreenWeb.js's SmartCoin class - click on the link for more info!
  • StandardCoin: Helper class used for making standard coins easier to use.
  • CAT: Helper class used for making Chia Asset Tokens (CATs) easier to use.
  • Singleton: Helper class used for making Singletons easier to use.
  • BigNumber: Export of the class that GreenWeb.js uses to handle big numbers (thanks to the ethers project for publishing their solution as a package).
  • Coin: The Coin class, as used by the Chia blockchain.
  • CoinSpend: The CoinSpend class, as used by the Chia blockchain.

Getting Started#

Browser - FireAcademy CDN#

Use the following snippet to include GreenWeb.js on a page:

<script src="https://assets.fireacademy.io/greenweb-1.1.9.js"></script>

Or just use the latest version (not recommended):

<script src="https://assets.fireacademy.io/greenweb.js"></script>

WARNING: GreenWeb.js is still a very young project. Expect breaking changes with every release.

Browser - Build it!#

To generate the latest greenweb.js file, clone the repository and use npm to build:

git clone https://github.com/Yakuhito/GreenWeb.js
cd GreenWeb.js
npm install
npm run build
ls -lah dist/greenweb.js

Copy dist/greenweb.js to your web directory. If you need to use clvm.initialize(), make sure to also include blsjs.wasm in the same directory - more about that here.

Use the following snippet to include GreenWeb.js on a page:

<script src="greenweb.js"></script>

Browser - npm#

This package can be added via npm:

npm install --save greenwebjs

For browser-based clients, you also need to install the buffer package and define the global Buffer class. For Vue.js 3, just add the following lines to App.vue:

<script setup lang="ts">
import { Buffer } from "buffer";
(window as any).Buffer = Buffer;
</script>

OR

<script setup>
import { Buffer } from "buffer";
window.Buffer = Buffer;
</script>

Unfortunately, most setups have issues when GreenWeb.js is installed this way. If you're seeing an error that you cannot fix, just include the greenweb.js script from the FireAcademy CDN and use window.greenweb.

Node.js#

The package can be installed via npm:

npm install --save greenwebjs

Examples#

Please see each module's documentation for usage examples.