Skip to content

Installing HyperBEAM and WAO

Installing HyperBEAM

Follow the HyperBEAM docs and install HyperBEAM on your local machine. You could use one of the existing remote nodes, but you'll miss many important details in these tutorials since we'll literally crack open the internals.

Installing WAO

Create a WAO project that comes with the wao SDK and testing framework:

Terminal
npx wao create myapp && cd myapp

You can also create an empty directory and install wao and hbsig:

Terminal
mkdir myapp && cd myapp && yarn init && yarn add wao hbsig
mkdir test && touch test/hyperbeam.js

Edit package.json to enable ESM and test commands with the --experimental-wasm-memory64 flag and disable concurrency so the test won't try running multiple HyperBEAM nodes:

/package.json
{
  "name": "myapp",
  "version": "0.0.1",
  "type": "module",
  "scripts": {
    "test": "node --experimental-wasm-memory64 --test --test-concurrency=1",
    "test-only": "node --experimental-wasm-memory64 --test-only --test-concurrency=1",
    "test-all": "node --experimental-wasm-memory64 --test --test-concurrency=1 test/**/*.test.js"
  },
  "dependencies": {
	"hbsig": "^0.0.7",
    "wao": "^0.33.3"
  }
}

Writing Tests

Import the HyperBEAM and HB classes from wao to interact with your HyperBEAM node.

Make sure you have an Arweave wallet JWK at HyperBEAM/.wallet.json for the node operator account.

Also, set CWD in .env.hyperbeam, which should be the HyperBEAM node directory path relative to the root directory of your app.

/.env.hyperbeam
CWD=../HyperBEAM

Here's the minimum viable test code. The HyperBEAM class starts up a HyperBEAM node and kills it once your tests complete, creating a sandbox environment for each test suite.

/test/hyperbeam.test.js
import assert from "assert"
import { describe, it, before, after, beforeEach } from "node:test"
import { HyperBEAM } from "wao/test"
 
describe("HyperBEAM", function () {
  let hbeam, hb
 
  // start a hyperbeam node and wait till it's ready, reset node storage
  before(async () => {
    hbeam = await new HyperBEAM({ reset: true }).ready()
    hb = hbeam.hb
  })
 
  // kill the node after testing
  after(async () => hbeam.kill())
 
  it("should run a HyperBEAM node", async () => {
    // change config
    await hb.post({ path: "/~meta@1.0/info", test_config: "abc" })
 
    // get config
    const { out } = await hb.get({ path: "/~meta@1.0/info" })
    assert.equal(out.test_config, "abc")
  })
})

You can interact with any HyperBEAM node from JS using the HB class.

With these two classes, you can write complete test suites for your HyperBEAM node, devices, processes, and modules running on top (such as AOS) using only JavaScript.

If you can't run HyperBEAM on your local machine, skip the HyperBEAM class and pass the remote node url to HB:

/test/hb.test.js
import assert from "assert"
import { describe, it, before, after } from "node:test"
import { acc } from "wao/test"
import { HB } from "wao"
 
describe("HyperBEAM", function () {
  let hb
 
  // using one of the pre-generated non-operator accounts for test
  before(async () => {
    hb = new HB({ jwk: acc[0].jwk, url: "http://localhost:10001" })
  })
 
  it("should connect to a HyperBEAM node", async () => {
    // get build info
    const build = await hb.g("/~meta@1.0/build")
    assert.equal(build.node, "HyperBEAM")
  })
})

Running Tests

You can find the working test files for this chapter here:

Run tests:

Terminal
yarn test test/hyperbeam.test.js
# yarn test test/hb.testjs

Now we're ready to decode HyperBEAM.

References

General
WAO API