For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs.
Skip to content

Retrieve Data in the Browser

Experimental SDK. The browser SDK and its direct-browser protocol are experimental.

Retrieve a public image from the Autonomi Network and display it in a web page using the browser SDK. The connection runs in the browser through WebAssembly (WASM) and WebRTC; you do not need a wallet or a local daemon.

Use this example when your application needs to read and display data in a browser. The Browser SDK overview explains other uses. For server-side JavaScript, use the Node.js SDK; for a separate network service, use local-daemon clients.

Prerequisites

  • Node.js 22.12 or later and npm on your development computer. Visitors to the finished page do not need Node.js.

  • A Chromium-based browser with WebAssembly and WebRTC enabled.

  • An internet connection that permits WebRTC connections to public nodes.

This example only reads existing public data. It does not configure a wallet or request payment.

Steps

1. Create the project

Vite serves the JavaScript and WASM assets during development and bundles them for deployment.

This tutorial uses browser SDK 0.1.4 and Vite 8.3.5. The commands save these exact versions so reinstalling the project does not select a different version of either package.

In a terminal, run:

mkdir autonomi-browser-demo
cd autonomi-browser-demo
npm init -y
npm install --save-exact @withautonomi/[email protected]
npm install --save-dev --save-exact [email protected]

2. Add the page

Create index.html in the project directory:

3. Connect and retrieve the image

Create main.js alongside index.html:

The connection uses the SDK's bundled mainnet addresses. The capability check reports missing browser APIs; it does not test whether your connection can reach the nodes.

This example connects for each download to keep cleanup simple. An application that reads multiple files would usually connect once and reuse the client, then call close() when it is no longer needed.

The image's public address identifies its data, not its original filename or media type. The example supplies image/jpeg because this particular file is a JPEG.

4. Run the app

Start the development server:

Open http://127.0.0.1:5179 and select Download Lucky. The page loads the WASM client, connects, and retrieves the image. The button stays disabled while the operation is running.

On success, Lucky's image appears with:

The example stops waiting after three minutes and closes its client on both success and failure. That timeout is an application choice, not an SDK limit.

5. Build for deployment

Generate the static site and preview it locally:

Open http://127.0.0.1:5180 and repeat the download. To deploy, publish the contents of dist/ to an HTTPS static host, including the generated WASM and JavaScript assets. Vite's preview command is for checking the build locally, not running a production server.

Verify it worked

Confirm that Lucky's image appears, the status reads Downloaded 138931 bytes., and the download button becomes available again. The development server and the production preview should display the same image.

The browser retrieves the data directly from Autonomi nodes. Vite serves your application and its WASM assets, not the image file.

Common errors

Missing browser features: use a Chromium-based browser with WebAssembly and WebRTC enabled. The message lists the missing APIs.

WASM initialization fails: open the app through the development server rather than opening index.html as a local file. In a deployed build, check that the .wasm request returns the generated binary, not an HTML fallback page.

Node protocol not supported: an error saying upgrade ant-node to a version advertising chunk_protocol means the contacted node lacks a capability this SDK needs. On the public Autonomi Network, updating those nodes is not something your application controls. Check the browser SDK release notes for compatibility guidance; if they do not resolve the problem, report the full error to the SDK maintainers.

Connection failure or timeout: check whether your connection permits WebRTC traffic. A failure to reach nodes or retrieve the file does not establish that the file is missing. Inspect the browser console for the original error, then retry when connectivity is available.

Next steps

Last updated