SDK Overview
Which package to install
| You are building | Install | Notes |
|---|---|---|
| A Decentraland SDK 7 scene | @virvixr/dcl (2.24.0) from npm | See Decentraland Setup. |
| A Hyperfy world | The Virvi app (virvi.hyp) | Downloaded from your Virvi server, not npm. See Hyperfy Setup. |
| A script, bot or backend | @virvixr/sdk (0.1.0) from npm, or nothing | The typed client for the REST API, or call the API directly with an API key. |
| A platform that can only make HTTP calls | Nothing | Use the platform hooks (/hook/*). |
| Support for a new platform | The monorepo | See Building an Adapter. |
The packages inside
@virvixr/dcl bundles the workspace packages below. They live in packages/ in the repo, are marked private, and are not published to npm on their own: import from @virvixr/dcl in a Decentraland scene.
| Package | Purpose |
|---|---|
@virvixr/shared | Types, enums, the VirviPlatformAdapter interface, protocol types |
@virvixr/client | HTTP client (VirviHttpClient) and Colyseus WebSocket manager |
@virvixr/core | The Virvi class, SceneManager, element managers (video, image, model, sound, ad space) |
@virvixr/hud | The in-world management HUD |
@virvixr/adapter-dcl | The Decentraland SDK 7 adapter and createVirvi() |
@virvixr/hyperfy-app | Builds the Hyperfy app (virvi.hyp) |
How it works
createVirvi()makes a platform adapter and aVirviinstance.- It signs in to the Virvi server with the platform’s identity (in Decentraland, a signed request from the player’s wallet).
- It joins the scene’s real-time room (
virvi_scene) and receives the live preset. - Core’s element managers call the adapter to draw every element.
- When someone edits the scene in the dashboard or the HUD, the room sends the change and core applies it.
import { createVirvi, type Virvi } from '@virvixr/dcl'
/** Run fn once Virvi has joined the scene's room (now, if it already has). */function whenConnected(virvi: Virvi, fn: () => void) { if (virvi.connectionState === 'connected') return fn() const off = virvi.onStateChange((state) => { if (state === 'connected') { off(); fn() } })}
export async function main() { const virvi = await createVirvi()
// Handlers can be added at any time virvi.onMessage('game-event', (data) => console.log('got', data))
// Sending needs the room: before it is joined, sendMessage throws "Not in a room" whenConnected(virvi, () => virvi.sendMessage('game-event', { score: 100 }))
// A custom analytics event virvi.track('level-complete', { level: 3 })}createVirvi() can resolve before the scene has loaded: for example while the owner sees “Set up Virvi here”, or while it connects in the background. Wait for connected, as above, before you send messages or read storage.
The Virvi object
What createVirvi() resolves to. These are the members meant for scene code.
| Member | What it does |
|---|---|
sendMessage(id, data?) | Sends data to every other client in the scene’s room. Not to yourself. See Multiplayer Events. |
onMessage(id, callback) | Calls callback(data, from) when a message with that id arrives; from is the server-stamped sender (2.24.0). One callback per id; a second call replaces the first. Returns a remover (2.24.0). |
offMessage(id, callback?) | From 2.24.0: stops listening for id. |
track(name, props?) | Records a custom analytics event. |
recordAction(id, metadata?) | Deprecated name for track(). |
storage | Read-only view of the scene’s elements. See Storage. |
state | From 2.24.0: the scene’s shared, saved key-value store (get, all, set, delete, on). See Scene State. |
onWidgetChange(id, listener), onWidgetClick(id, listener) | From 2.24.0: a dashboard widget’s changes and Trigger presses. See Widgets. |
onElementCreate, onElementUpdate, onElementDelete, onStorageChange | From 2.24.0: draw elements yourself, and hear every change to the scene’s elements. See Custom Rendering. |
sceneId | The connected Virvi scene’s ID, or null. |
user | The signed-in user (id, displayName, role), or null. |
connectionState | idle, authenticating, authenticated, discovering_scene, scene_ready, connecting, connected or error. |
onStateChange(listener) | Calls listener(state, detail?) on every change. Returns a function that removes it. |
onActivePresetChanged(listener) | Calls listener(presetId) when the live preset changes. Returns a remover. |
destroy() | Leaves the room and stops. |
state is one set of values for the whole scene; there is no per-player store. Keep per-player data on your own backend.
Storage
virvi.storage holds the live preset’s elements, keyed by each element’s custom ID (or its internal key when it has none). Each store has configs (elements) and instances (placed copies).
virvi.storage.videos.configs['my-screen']virvi.storage.images.configs['banner']virvi.storage.models.configs['trophy']virvi.storage.sounds.configs['ambient']The stores are videos, images, models, sounds, adSpaces, nfts, claimPoints and widgets. The SDK fills the first five. Read them; don’t write to them.