0.0.8 • Published 7 months ago
@freenetorg/freenet-stdlib v0.0.8
Locutus Javascript/Typescript Std Lib
Locutus Javascript/Typescript Standard Library contains utilities for developing web apps which interact with Locutus node.
The stdlib offers a series of facilities in which you will be able to communicate with the network ergonomically.
Here is a minimal example of how you could write your application to interact with the node:
import {
GetResponse,
HostError,
Key,
FreenetWsApi,
PutResponse,
UpdateNotification,
UpdateResponse,
} from "@freenetorg/freenet-stdlib/websocket-interface";
const handler = {
onPut: (_response: PutResponse) => {},
onGet: (_response: GetResponse) => {},
onUpdate: (_up: UpdateResponse) => {},
onUpdateNotification: (_notif: UpdateNotification) => {},
onErr: (err: HostError) => {},
onOpen: () => {},
};
const API_URL = new URL(`ws://${location.host}/contract/command/`);
const locutusApi = new FreenetWsApi(API_URL, handler);
const CONTRACT = "DCBi7HNZC3QUZRiZLFZDiEduv5KHgZfgBk8WwTiheGq1";
async function loadState() {
let getRequest = {
key: Key.fromSpec(CONTRACT),
fetch_contract: false,
};
await locutusApi.get(getRequest);
}