Skip to content

SDK Overview

Which package to install

You are buildingInstallNotes
A Decentraland SDK 7 scene@virvixr/dcl (2.24.0) from npmSee Decentraland Setup.
A Hyperfy worldThe 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 nothingThe typed client for the REST API, or call the API directly with an API key.
A platform that can only make HTTP callsNothingUse the platform hooks (/hook/*).
Support for a new platformThe monorepoSee 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.

PackagePurpose
@virvixr/sharedTypes, enums, the VirviPlatformAdapter interface, protocol types
@virvixr/clientHTTP client (VirviHttpClient) and Colyseus WebSocket manager
@virvixr/coreThe Virvi class, SceneManager, element managers (video, image, model, sound, ad space)
@virvixr/hudThe in-world management HUD
@virvixr/adapter-dclThe Decentraland SDK 7 adapter and createVirvi()
@virvixr/hyperfy-appBuilds the Hyperfy app (virvi.hyp)

How it works

  1. createVirvi() makes a platform adapter and a Virvi instance.
  2. It signs in to the Virvi server with the platform’s identity (in Decentraland, a signed request from the player’s wallet).
  3. It joins the scene’s real-time room (virvi_scene) and receives the live preset.
  4. Core’s element managers call the adapter to draw every element.
  5. 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.

MemberWhat 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().
storageRead-only view of the scene’s elements. See Storage.
stateFrom 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, onStorageChangeFrom 2.24.0: draw elements yourself, and hear every change to the scene’s elements. See Custom Rendering.
sceneIdThe connected Virvi scene’s ID, or null.
userThe signed-in user (id, displayName, role), or null.
connectionStateidle, 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.