Comment on page

Server-Hosted Skynet Usage


Most of this documentation assumes you're interacting with Skynet from a client-side, browser context, using skynet-nodejs. This guide will walk you through some of the main considerations of interacting with Skynet from a server-side context.
If you are working with us as a partner, please reach out to [email protected] (Discord dghelm#8125) for a promo code for a free elevated tier account.
Previous versions of this page recommended mixing skynet-js and skynet-nodejs usage in a single project. We now suggest developers only use one or the other, depending on how their code will be run. Skynet API Keys are now widely supported and are considered best practice over the previous suggestion of using JWTs.

Skynet SDK Capabilities

Currently, only our NodeJS SDK has all the features addressed in this article.
Skyfile Upload
Skyfile Download
MySky + DACs
Large File Upload (tus)
Registry Access
Resolver Skylink Set
Portal Account
File Pinning
Looking to contribute? Many of these features are thin abstractions over our HTTP APIs. Take a look at open issues in the Python SDK and Go SDK.

File Uploads

skynet-js currently only supports browser uploads. You will want to upload files using one of our other SDK or CLI tools (ie @skynetlabs/skynet-nodejs).
The node SDK has been updated to support large file uploads in version 2.1.0. The tus protocol will automatically be used for any file >40MB.

File Persistence

In a browser context, cookies containing encrypted JWTs are used for linking file uploads to your portal account. This is needed for pinning files >90 days or accessing account-only portals.
Outside of the browser context (or if cookies are not supported), you will want to upload your file using a Skynet API Key which can be generated in the Developer Settings of your portal's account dashboard.
For more information on generating and using a portal API key, please see the API & Sponsor Keys page.
To pin a skylink, first initialize your Skynet Client to use your Skynet API Key. After initializing the client, call client.pinSkylink(skylink);
One common use-case for server-side applications is to upload files that are pointed to using a resolver skylink, so that the data can be consumed using a consistent URL.
Here is a code example:
const { SkynetClient, genKeyPairFromSeed } = require("@skynetlabs/skynet-nodejs");
const { SKYNET_JWT, SECRET_SEED } = require './consts';
const portal = '';
const client = new SkynetClient(portal, { customCookie: SKYNET_JWT })
// Setup Keys for Read/Write of Mutable Data
const { privateKey, publicKey } = genKeyPairFromSeed( SECRET_SEED );
const dataKey = 'nameForRegistryEntry';
// skylink to point to with resolver skylink
const skylink = "sia://MABdWWku6YETM2zooGCjQi26Rs4a6Hb74q26i-vMMcximQ";
// Set Registry Entry to point at our Skylink
await client.db.setDataLink(privateKey, dataKey, skylink);
// Get the resolver skylink that represents the registry entry
const resolverSkylink = await client.registry.getEntryLink(publicKey, dataKey);
// Get the URL for the resolver skylink, at ``
const resolverSkylinkUrl = await client.getSkylinkUrl(resolverSkylink);