Build Apps with Node.js

This guide will help you get started with building apps with Autonomi starting from scratch. This guide has 4 parts:

circle-info

This has guide has been tested on MacOS and Linux, but the commands might be slightly different for Windows (unless you are using WSLarrow-up-right).

Prerequisites

First let's install the required tools to get started:

Once Node.js is installed, let's proceed to create a local testnet.

Create a local testnet

See Local Network Setup.

Connect to the testnet with Node.js

Let's create a Node.js project that interacts with the testnet. First let's setup a working environment and install the @withautonomi/autonomiarrow-up-right package.

Then create a new Node.js file in which we will write our app:

Open up the file in your favorite editor and add the following code:

In your terminal, run the following command to execute the script:

You should see the following output:

Congrats! You've just connected to the testnet! 🎉

Upload and retrieve data with Node.js

Next up let's upload some data to the testnet and retrieve it. We will be using the Autonomi data API for this. Expanding upon our previous work, change the main.mjs file to the following:

For private data, use the dataPut and dataGet methods instead!

Congrats! If you got this far, you are ready to start building apps that can store data on Autonomi! 🎉

Working with Registers

Registers are mutable data structures that allow you to store updateable content with versioned history. Here's how to use them:

Key Register Features:

  • Mutable: Can be updated with new content while preserving history

  • Versioned: All previous versions are permanently accessible

  • Owned: Only the key holder can update the register

  • 32-byte limit: Each register value is limited to 32 bytes

  • Paid updates: Both creation and updates require payment

Common Register Use Cases:

  1. Application Configuration: Store app settings that need updates

  2. Status Tracking: Maintain current state with full history

  3. Version Control: Track document versions

  4. Counters: Implement distributed counters

  5. Metadata: Store changeable file or app metadata

Register API Methods:

  • client.registerCost(publicKey) - Calculate creation cost

  • client.registerCreate(key, content, payment) - Create new register

  • client.registerGet(address) - Get current register value

  • client.registerUpdate(key, content, payment) - Update register content

  • client.registerHistory(address) - Get version history iterator

  • Client.registerKeyFromName(mainKey, name) - Generate deterministic key

  • Client.registerValueFromBytes(buffer) - Create RegisterValue from Buffer

Last updated