HB
HB handles interactions with a Hyperbeam node.
Instantiate
import { HB } from "wao"
const hb = await new HB({ url: "http://localhost:10001" }).init(jwk)Constructor Parameters
| Param | Default | Description |
|---|---|---|
url | "http://localhost:10001" | HyperBEAM URL |
cu | "http://localhost:6363" | Compute Unit URL |
jwk | - | Wallet JWK (can also set via init) |
format | "httpsig" | "httpsig" or "ans104" |
const hb = await new HB({
url: "http://localhost:10001",
cu: "http://localhost:6363",
format: "httpsig"
}).init(jwk)HTTP Requests
get
Send a GET request without a signed http message. You can get the decoded data in out.
out = decode( headers, body )
const { out, headers, body } = await hb.get({ path, ...params})post
Send a POST request with a signed http message. data will be set to http body with auto-generated content-digest and inline-body-key in the header.
const { out, headers, body, hashpath } = await hb.post({ path, ...fields})g
A shortcut for get.
const out = await hb.g( path, params )p
A shortcut for post.
const out = await hb.p( path, params )getJSON
GET with automatic JSON parsing.
const data = await hb.getJSON({ path, ...params })postJSON
POST with automatic JSON parsing.
const data = await hb.postJSON({ path, ...params })Processes
spawn
Spawn a process.
const { pid } = await hb.spawn({ ...tags })schedule
Equivalent to sending a message.
const { slot } = await hb.schedule({ tags, data, pid })compute
Equivalent to getting a result.
const res = await hb.compute({ pid, slot })message
message = schedule + compute.
const { pid, slot, res } = await hb.message({ tags, data, pid })now
Compute up to the latest slot.
const res = await hb.now({ pid })slot
Get the current slot number/state at a path.
const state = await hb.slot({ pid, path })messages
Get messages on a process. You can get next messages by msgs.next.
const msgs = await hb.messages({ pid, from, to })
for(const item of msgs.edges){
const { cursor: slot, node: { assignment, message } } = item
}
if(msgs.next) const msgs2 = await msgs.next()pid: a process idfrom|to: the slot numbers. Messages are marked by integer on HB, not by txid.0is theType=Processmessage that spawned the process.tois inclusive. Both are optional.
results
Get multiple results from the Compute Unit. sort defaults to "DESC".
const res = await hb.results({ process, limit, sort, from, to })Caching
cacheBinary
Cache binary data (WASM, images) to the HyperBEAM node. Returns the cache ID.
const cacheId = await hb.cacheBinary(data, type)cacheScript
Cache a Lua script. Returns the message ID.
const msgId = await hb.cacheScript(data, type)type defaults to "application/lua".
getImage
Fetch and cache the AOS WASM image. Returns the image ID.
const imageId = await hb.getImage()getLua
Fetch and cache the Lua module. Returns the module ID.
const luaId = await hb.getLua()Signing & Sending
sign
Sign a message without sending it.
const signed_msg = await hb.sign(msg)signEncoded
Sign a pre-encoded message object.
const signed = await hb.signEncoded(encoded)send
Send a signed message.
const res = await hb.send(signed_msg)commit
Sign a message with commitments.
const committed_msg = await hb.commit(msg)Info
setInfo
Fetch the operator address and populate this.operator, this.image, and this.lua.
await hb.setInfo()
console.log(hb.operator) // operator addressisArConnect
Check if the wallet is an ArConnect browser wallet.
const isWallet = hb.isArConnect()Legacynet AOS
spawnLegacy
Spawn Legacynet AOS.
const { pid } = await hb.spawnLegacy({ tags, data })scheduleLegacy
Schedule a legacynet aos message.
const { slot } = await hb.scheduleLegacy({ tags, data, pid, action })computeLegacy
Compute legacynet AOS state.
const res = await hb.computeLegacy({ pid, slot })
const { Messages, Spawns, Assignments, Output } = resmessageLegacy
messageLegacy = scheduleLegacy + computeLegacy. Returns { slot, res }.
const { slot, res } = await hb.messageLegacy({ tags, data, pid, action })dryrun
dryrun is only for legacynet AOS. Mainnet AOS disabled this feature for a performance reason.
const res = await hb.dryrun({ tags, data, pid, action })
const { Messages, Spawns, Assignments, Output } = resHyper AOS
AOS with Lua VM (lua@5.3a) instead of Wasm.
spawnLua
The AOS module is fetched from the Arweave mainnet.
const { pid } = await hb.spawnLua()scheduleLua
This is an alias of scheduleLegacy.
const { slot } = await hb.scheduleLua({ tags, data, pid, action })computeLua
const { outbox, output } = await hb.computeLua({ slot, pid })Mainnet AOS
Mainnet AOS processes have dedicated API.
spawnAOS
const { pid } = await hb.spawnAOS()messageAOS
messageAOS = scheduleAOS + computeAOS. Returns { slot, outbox }.
const { slot, outbox } = await hb.messageAOS({ pid, action, tags, data })pushAOS
JS-side push for AOS processes. Resolves cross-process round-trips (A→B→A) for receive() resolution.
const { slot, outbox } = await hb.pushAOS({ pid, slot, outbox, maxDepth })outbox: optional initial outbox from a priorcomputeAOScallmaxDepth: max resolution depth (default10)
computeAOS
const result = await hb.computeAOS({ pid, slot })scheduleAOS
Schedule for mainnet AOS. An alias that sets the Action tag.
const { slot } = await hb.scheduleAOS({ pid, action, tags, data })Format-Specific Scheduling
scheduleFlat
Schedule with the flat codec.
const { slot, res, pid } = await hb.scheduleFlat({ pid, tags, data })scheduleNP
Schedule for the node-process device.
const { slot, res, pid } = await hb.scheduleNP({ pid, tags, data })ANS-104
post104
POST in ANS-104 bundle format.
const res = await hb.post104({ path, tags, data, target })send104
Send a pre-built ANS-104 item.
const res = await hb.send104({ path, item })