reference

Class: GolemNetwork

golem_network/golem_network.GolemNetwork

The starting point for using Golem Network.

Description

The GolemNetwork class is the best way to get started with developing on Golem Network. It provides a simple interface for creating jobs and running tasks.

Example

import { GolemNetwork } from "@golem-sdk/golem-js";
const network = new GolemNetwork();
network.init().then(() => {
 // network is ready to use
 const result = await network.runTask(async (ctx) => {
  // do some work
  return (await ctx.run("echo 'Hello from Golem'")).stdout;
 });
 console.log(result);
});

Table of contents

Constructors

Methods

Constructors

constructor

new GolemNetwork(config)

Parameters

NameType
configGolemNetworkConfig

Defined in

src/golem_network/golem_network.ts:58

Methods

isInitialized

isInitialized(): boolean

Returns

boolean

Defined in

src/golem_network/golem_network.ts:67


init

init(): Promise<void>

Returns

Promise<void>

Defined in

src/golem_network/golem_network.ts:71


createJob

createJob<Output>(worker): Promise<Job<Output>>

Create a job on Golem Network.

Type parameters

NameType
Outputunknown

Parameters

NameTypeDescription
workerWorker<unknown, Output>Worker function to run

Returns

Promise<Job<Output>>

Job object

Description

Create a job on Golem Network. You can use the job object to fetch the job status, results and errors. For more information see Job.

Example

const job = await network.createJob(async (ctx) => {
// do some work
return (await ctx.run("echo 'Hello from Golem'")).stdout;
});
console.log(job.id);
const status = await job.fetchState();
console.log(status);

Defined in

src/golem_network/golem_network.ts:101


getJobById

getJobById(id): Job<unknown>

Parameters

NameType
idstring

Returns

Job<unknown>

Defined in

src/golem_network/golem_network.ts:105


runTask

runTask<Output>(worker): Promise<undefined | Output>

Run a task on Golem Network.

Type parameters

NameType
Outputunknown

Parameters

NameTypeDescription
workerWorker<undefined, Output>Worker function to run

Returns

Promise<undefined | Output>

Worker function result

Description

The runTask method is the simplest way to run some code on Golem Network. Simply call runTask and await the promise to get your result.

Defined in

src/golem_network/golem_network.ts:116


close

close(): Promise<void>

Returns

Promise<void>

Defined in

src/golem_network/golem_network.ts:120