Spawn

Register a program to run on Aleph.im virtual machines.

Description

With the Spawn() functionnality you can launch aleph virtual machine without uploading the code by yourself.

Be aware about the ownership of the source code you are using.

If you use a code from an Aleph message you don't own, know that this code can be amend or deleted at any time by it owner.

Usage

Import the Spawn declaration to interact with the Spawn function and the Item type to choose your storage location.

import { messages } from 'aleph-sdk-ts';

// Or used optimized import
import { Spawn } from 'aleph-sdk-ts/dist/messages/program';

Then call the Spawn function, with the required parameters as follow:


(async() => {
  const res = await Spawn({
      account: account,
      channel: "TEST",
      entrypoint: "main:app" // This value referred to the `Basic Progam` example
      programRef: "560506e91349712a8338440c0df3c74c17d1b797183ffc34797887d1d4470130",
  })

})

Required Parameters

account - required Account

Account to use for signing.

channel - required string

Channel of the message. Ideally, an application would decide and use one channel.

programRef - required string

A message hash of a store message that contain the code to deploy.

entrypoint - required string

The entrypoint is composed of two values:β€’ The name of the main file that is running the programβ€’ The name of the object in the program that inits FastApi Ex: <mainFile:FastApiObject>. Learn more about FastApi here.

subscription - optional Record<string, unknown>

DEFAULT: { http: true } Signals that trigger an execution of the VM, by default it's triggered by HTTP, but it can be by an Aleph Message. Ex: Record<"message", [{"sender: "0x...", "channel": "TEST"}]>

memory - optional number

DEFAULT: 128 The memory you give to your VM, this param is contained in the MachineResources struct.

runtime - optional string

DEFAULT: "bd79839bf96e595a06da5ac0b6ba51dea6f7e2591bb913deccded04d831d29f4" This param refers to the root filesystem used by the Aleph VM and this param is a path to them, you can find the official Aleph runtimes here

volumes - optional array of MachineVolume

MachineVolume can either be: ImmutableVolume | EphemeralVolume | PersistentVolume. Explanation of those types are here. You can also find their definition here.

storageEngine - optional ItemType

A location to store the message if inlineRequested is False or your message exced the Max_size (~50 000kb).

inlineRequested - optinal boolean

If True, the message itself will be stored inline, if False it will be store in the same destination as the storageEngine.​

APIServer - optional string

The API server endpoint used to carry the request to the Aleph's network.

Return

After spawning your program, you can find it on the Aleph Explorer. This is an example of a Hello world test.

When you are spawning a Program Message, the function returns the transaction. Inside it, you can find the item_hash field that is referring to your program location.

# Url format:
https://aleph.sh/vm/{Your program item_hash}

#Example of the Hello World program:
https://aleph.sh/vm/5d9dfafd5598a4a6b1c3f5b9a79023a783d60d73ac65d695d7e573ad048fc0f1

You can "pin" your programs' hashes with a Post message for example with some tags and references to allow you to retrieve them easily.

Last updated