Quickstart

Golem JS Quickstart

Introduction

In this article, we'll show you how to run a simple task on the Golem Network.

As a Quickstart, we will perform a simple task: running a basic shell command on a rented provider.

It should take just a few minutes to complete, and you will see the command output printed in your terminal.

Installing and running Yagna

Yagna is a service that communicates and performs operations on the Golem Network. Let's get started by installing it.

Install Yagna

On Linux/ MacOS, you can install it using our installation script like this:

curl -sSf https://join.golem.network/as-requestor | bash -

You might be asked to modify your PATH afterward.

info

Should you encounter any problems, please reach out to us via our Discord channel or consult the following resource for troubleshooting.

Start the Yagna service

Open a terminal (command line window) and define the app-key that will allow our script to use the Yagna API:

export YAGNA_AUTOCONF_APPKEY=try_golem

Then start the yagna service:

yagna service run

Get test GLM tokens

Requesting tasks on the Golem Network requires GLM tokens. As this example will run on a test network, you can use test GLM.

Open another terminal and run the following command to complete the configuration:

yagna payment fund

It will top up your account with test GLM tokens. These tokens can only be used on the testnet.

Building your first Golem Network App

Create a new Node.js project and install the Golem SDK by entering the following commands in your terminal:

mkdir try_golem
cd try_golem
npm init
npm install @golem-sdk/task-executor

Please note: This application requires Node.js version 18.0.0 or higher.

Create a file named requestor.mjs and copy the following content into it. The code defines a task that runs the command node -v on the Golem Network and prints the result to your terminal.

import { TaskExecutor, pinoPrettyLogger } from "@golem-sdk/task-executor";
(async () => {
  const executor = await TaskExecutor.create({
    package: "golem/node:20-alpine",
    logger: pinoPrettyLogger(),
    yagnaOptions: { apiKey: "try_golem" },
  });
  try {
    const result = await executor.run(async (ctx) => (await ctx.run("node -v")).stdout);
    console.log("Task result:", result);
  } catch (err) {
    console.error("An error occurred:", err);
  } finally {
    await executor.shutdown();
  }
})();
info

You can find a detailed explanation of the above code here

Running the script on Golem Network

Run the command:

node requestor.mjs

The output of the script should look very similar to the one below:

Output logs

The information about the node.js version included in the image that our script deploys on the remote computer, can be found at the end of the script's logs.

Summary

You've installed the Yagna service and executed a simple task on the Golem Network. However, you can accomplish much more. Here are some suggested next steps to explore the Golem Network world: