Become a Requestor in the Golem Network and use this SDK to:
- π Acquire compute resources from Providers using a convenient API
- π’ Run your workloads with these resources and get the results back to your machine
- π Build N-tier application deployments and run them within a VPN
- π° Settle payments with Providers for the resources you've utilized
The Golem Network fosters a global group of creators building ambitious software solutions that will shape the technological landscape of future generations by accessing computing resources across the platform. Golem Network is an accessible, reliable, open access and censorship-resistant protocol, democratizing access to digital resources and connecting users through a flexible, open-source platform.
golem-js is the JavaScript API that allows developers to connect to their Golem nodes and manage their distributed, computational loads through Golem Network.
- Basic concepts documentation - Learn about the basic and advanced building blocks at your disposal.
- Usage documentation - Explore supported usage and implementation patterns.
- Feature documentation - Description of interesting features that we've prepared.
To quickly get started with a new project using golem-js
, you can use the following template:
npx @golem-sdk/cli@latest new my-awesome-golem-project
@golem-sdk/golem-js
is available as a NPM package.
You can install it through npm
:
npm install @golem-sdk/golem-js
or by yarn
:
yarn add @golem-sdk/golem-js
The SDK is designed to work with LTS versions of Node (starting from 18)
and with browsers. The minimum supported yagna
version is 0.15.2
.
Before you start using the SDK, you need to have yagna
installed and running on your machine. Yagna is a service that
communicates and performs operations on the Golem Network, upon your requests via the SDK. You can follow the
instructions below or visit
the official documentation
to set it up.
# Join the network as a requestor
curl -sSf https://join.golem.network/as-requestor | bash -
# Start the golem node on your machine,
# you can use `daemonize` to run this in background
yagna service run
Now that you have yagna
running, you can initialize your requestor and request funds (tGLM
tokens) on the test
network.
# IN SEPARATE TERMINAL (if not daemonized)
# Initialize your requestor
yagna payment init --sender --network holesky
# Request funds on the test network
yagna payment fund --network holesky
# Check the status of the funds
yagna payment status --network holesky
If you don't have any app-keys available from yagna app-key list
, go ahead and create one with the command below.
You will need this key in order to communicate with yagna
from your application. You can set it
as YAGNA_APPKEY
environment variable.
yagna app-key create my-golem-app
You can rent a single machine and run a simple task on it:
import { MarketOrderSpec, GolemNetwork } from "@golem-sdk/golem-js";
// Define the order that we're going to place on the market
const order: MarketOrderSpec = {
demand: {
workload: { imageTag: "golem/alpine:latest" },
},
market: {
// We're only going to rent the provider for 5 minutes max
rentHours: 15 / 60,
pricing: {
model: "linear",
maxStartPrice: 0.5,
maxCpuPerHourPrice: 1.0,
maxEnvPerHourPrice: 0.5,
},
},
};
(async () => {
const glm = new GolemNetwork();
try {
await glm.connect();
// Rent a machine
const rental = await glm.oneOf({ order });
await rental
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem! π"))
.then((res) => console.log(res.stdout));
await rental.stopAndFinalize();
} catch (err) {
console.error("Failed to run the example", err);
} finally {
await glm.disconnect();
}
})().catch(console.error);
Read about other available usage patterns to learn more on how you can leverage the SDK.
The examples directory in the repository contains various usage patterns for the SDK. You can browse through them and learn about the recommended practices. All examples are automatically tested during our release process.
You can find even more examples and tutorials in the JavaScript API section of the Golem Network Docs.
Visit our official documentation to learn more about the JavaScript SDK and how to use it.
The SDK uses the debug package to provide debug logs. To enable them, set
the DEBUG
environment variable to golem-js:*
or golem-js:market:*
to see all logs or only the market-related ones,
respectively. For more information, please refer to
the debug package documentation.
Read the dedicated testing documentation to learn more about how to run tests of the SDK.
Read the Contributing Guide for details on how you can get involved. In case you find an issue with the examples or the SDK itself, feel free to submit an issue report to the repository.
Feel invited to join our Discord. You can meet other SDK users and developers in the #sdk-discussion
and #js-discussion
channels.
- Golem, a global, open-source, decentralized supercomputer that anyone can access.
- Learn what you need to know to set up your Golem requestor node:
- Have a look at the most important concepts behind any Golem application: Golem application fundamentals
- Learn about preparing your own Docker-like images for the VM runtime
- Write your own app with JavaScript API