Golem Network manual for Degen Hack hackathon participants.

info

This section contains an extract from the Golem Network documentation for Degen Hack hackathon participants. The full version is available on the Golem Docs portal and specifically JS related documentation can be found here.

Should you encounter any problems, please reach out to us via our Degen Hack hackathon Discord channel or consult the Golem representative present on-site during the event.

Intro to Golem Network and JS API.

Golem Network is a P2P network that consists of many nodes. Each node is a system with a Yagna service running on it. The nodes that offer their resources to others are called providers. The nodes that rent resources are called requestors.

Yagna is a service that enables the user to interact with the network. In practice, the user creates a requestor script utilizing one of the available Golem SDKs. The script is used to define what resources are needed and what should be run on the provider's node, and to orchestrate all activities.

For the resources consumed on the Golem Network, you pay in GLM. GLM is an ERC-20 utility token. When you run Yagna for the first time on your computer, it will create a wallet for you. It will have an address on supported blockchains and you can export the wallet address to an external application.

When developing your code on the Golem Network you do not necessarily need to acquire GLM tokens. You can use the testnet network, which while consisting of providers of some limited performance allows you to pay in tGLM available for free. Once your code is ready for production, you switch to mainnet, where you need true GLM.

Getting started:

Installing Yagna

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

curl -sSf https://join.golem.network/as-requestor | YA_INSTALLER_CORE=v0.13.2 bash -

You might be asked to modify your PATH afterward.

Start the Yagna service

To start the yagna service, open a terminal and type:

yagna service run

Get test GLM tokens

Requesting tasks on the Golem Network requires GLM tokens. When you use testnet you use test GLM. Open another terminal and run the following command:

yagna payment fund

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

A few additional useful steps and yagna commands

The steps below are not part of the installation process, however they will be useful at later stages:

Creating a unique app-key

The app-key purpose is to allow your requestor script to securely access and interact with the Yagna API Open a terminal (command line window) and create the app-key named requestor:

yagna app-key create requestor

After running this command, make sure to copy its output. This output is your app-key, which you will need to use for setting up the YAGNA_APPKEY environment variable.

export YAGNA_APPKEY=<32-char>

Note: If you need to find your key value again at any time, you can retrieve it using the following command:

yagna app-key list

and locate the desired value in the 'key' column for copying.

Getting the address of your wallet

To find out where to transfer funds for your Yagna wallet, you can easily obtain the address of your wallet with this command:

yagna payment accounts

This command is not only used to find your wallet address, but it also serves as the unique identifier of your node within the network.

Verifying Your Wallet's Balance

yagna payment status --network=holesky --driver=erc20

Backing up your Golem wallet

To create a backup of your Golem wallet, export the keystore with:

yagna id export --file-path=./key.json

This will generate a file named key.json in the directory where the command was run. This file contains the private key of your Golem wallet.

warning

Please store the key in a secure location and not share it with anyone as it gives full control over your Golem wallet and funds.

Running a Quickstart

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

npm init @golem-sdk/golem-app@latest my-golem-app

Make sure you have created an app-key and exported its value as YAGNA_APPKEY.

In src folder you will find a reaquestor script. This script sets up a task to execute node -v on the Golem Network and displays the result in your terminal.

import * as dotenv from "dotenv";
import { ProposalFilterFactory, TaskExecutor } from "@golem-sdk/task-executor";
import { pinoLogger } from "@golem-sdk/golem-js";

dotenv.config();

(async function main() {
  const executor = await TaskExecutor.create({
    // What do you want to run
    package: "golem/node:20-alpine",

    // How much you wish to spend
    budget: 2,

    // How do you want to select market proposals
    proposalFilter: ProposalFilterFactory.limitPriceFilter({
      start: 1.0,
      cpuPerSec: 1.0 / 3600,
      envPerSec: 1.0 / 3600,
    }),

    // Where you want to spend
    payment: {
      network: "goerli",
    },

    // Control the execution of tasks
    maxTaskRetries: 0,

    // Useful for debugging
    logger: pinoLogger({
      level: "info",
    }),
    taskTimeout: 5 * 60 * 1000,
  });

  try {
    // Your code goes here
    const result = await executor.run((ctx) => ctx.run("node -v"));
    console.log("Version of NodeJS on Provider:", (result!.stdout as string).trim());
  } catch (err) {
    console.error("Running the task on Golem failed due to", err);
  } finally {
    await executor.shutdown();
  }
})();

To execute the script, run:

npm start

You can find an explanation of the structure of the typical requestor script here.

The standard quickstart example has been altered with the following modifications:

  • payment: { network: 'holesky', }, indicates that we would like to run the task on the testnet.

  • it also utilizes a unique app-key stored in the YAGNA_APPKEY variable.

info

Please note that the default examples provided in the Golem Documentation are set up to use an automatically configured APP-KEY and are also intended to run on the testnet. You can adapt these examples to run on the mainnet by changing value of the payment.network option to polygon.

Golem JS SDK:

Components of the JS SDK

The JS SDK consists of the following components:

@golem-sdk/golem-js - a JavaScript API for developers allowing them to connect to their Golem nodes and manage their distributed, computational loads through Golem Network.

GitHub Repo Documentation

@golem-sdk/cli - a companion tool for the Golem SDK. It facilitates a fast start with Golem Network by creating a new template for new applications, assisting with manifest creation for outbound networking, and lets you interactively test your custom image in the fastest way possible all without coding.

GitHub Repo Documentation

@golem-sdk/react - a set of React hooks for working with the Golem Network.

GitHub Repo Documentation

JS API documentation including examples and API Reference:

Documentation

Examples

API Reference

JS SDK example projects

tesseract-ocr-golem - a golem-js based library for running Tesseract OCR jobs on the Golem Network.

GitHub Repo

react-image-classifier - a reference implementation of a React app using Golem underneath

GitHub Repo

music-on-golem - a reference implementation of a next.js app that uses Golem to generate music. The project contains everything you'd find in a typical full-stack application, including a database, design system, authentication, and more.

GitHub Repo

Golem tools

Yagna - the foundational service that allows users to connect with and interact with the Golem Network.

Gvmkit-build - a tool designed to create custom images for virtual machines on provider nodes within the Golem Network. It specifically converts Dockerfiles into Golem-compatible VM images, known as GVMI.

You find a list of available instructions for Golem tools here.

Golem Registry - a repository of already built images that can be utilized by Golem Network users is here.

Was this helpful?