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
Name | Type |
---|---|
config | GolemNetworkConfig |
Defined in
src/golem_network/golem_network.ts:36
Methods
isInitialized
▸ isInitialized(): boolean
Returns
boolean
Defined in
src/golem_network/golem_network.ts:50
init
▸ init(): Promise
<void
>
Returns
Promise
<void
>
Defined in
src/golem_network/golem_network.ts:54
createJob
▸ createJob<Output
>(worker
): Promise
<Job
<Output
>>
Create a job on Golem Network.
Type parameters
Name | Type |
---|---|
Output | unknown |
Parameters
Name | Type | Description |
---|---|---|
worker | Worker <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:82
getJobById
▸ getJobById(id
): Job
<unknown
>
Parameters
Name | Type |
---|---|
id | string |
Returns
Job
<unknown
>
Defined in
src/golem_network/golem_network.ts:86
runTask
▸ runTask<Output
>(worker
): Promise
<undefined
| Output
>
Run a task on Golem Network.
Type parameters
Name | Type |
---|---|
Output | unknown |
Parameters
Name | Type | Description |
---|---|---|
worker | Worker <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:97
close
▸ close(): Promise
<void
>
Returns
Promise
<void
>