Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@permaweb/hyperbeam-loader

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@permaweb/hyperbeam-loader

This module takes an `ao` Wasm `ArrayBuffer` and returns a `handle` function, that given `SmartWeaveContract` inputs, will produce a `result`.

latest
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

ao Wasm Loader

This module takes an ao Wasm ArrayBuffer and returns a handle function, that given SmartWeaveContract inputs, will produce a result.

The handle function can be invoked just like any other SmartWeaveContract

Usage

The @permaweb/ao-loader MUST receive an ArrayBuffer that contains the Wasm to be invoked:

import AoLoader from "@permaweb/ao-loader";

/* SmartWeave READ-ONLY Env Variables */
const SmartWeave = {
  transaction: {
    id: "1",
  },
};

// Create the handle function that executes the Wasm
const handle = AoLoader(wasmBinary);

// Now invoke the handle
const result = await handle({ balances: 1 }, {
  caller: "1",
  input: { function: "balance" },
}, SmartWeave);

Using a File

You can use fs to a load a Wasm file from the local filesystem as a Node Buffer. Since a Node Buffer implements ArrayBuffer, it can be passed directly to the AoLoader directly!

To get back a Node Buffer, make sure to NOT pass an encoding parameter to readFile

import AoLoader from "@permaweb/ao-loader";
import fs from "fs";

async function main() {
  const wasmBinary = fs.readFileSync("contract.wasm");
  const handle = AoLoader(wasmBinary);
  const result = await handle(...);
}

Using fetch

You can also use native fetch to retrieve the Wasm as an ArrayBuffer. This is great if you're fetching a Wasm contract published on Arweave:

import AoLoader from "@permaweb/ao-loader";

async function main() {
  const tx_id = '...'
  const wasmBinary = await fetch(`https://arweave.net/${tx_id}`)
    .then(res => res.arrayBuffer())
  const handle = AoLoader(wasmBinary);
  const result = await handle(...)
}

FAQs

Package last updated on 19 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts