> ## Documentation Index
> Fetch the complete documentation index at: https://docs.musterbox.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Defold

> Integrate the MusterBox SDK with Defold 1.6.5+.

The Defold adapter (`musterbox-defold`, extension name `musterbox`) targets
**Defold 1.6.5+**. Package `musterbox-defold-1.0.0.zip`, FFI ABI 1.2.0.

## Install

Add the packaged library to `game.project` dependencies:

```bash theme={"dark"}
# dist/defold/musterbox-defold-1.0.0.zip
# Project > Dependencies > Add -> local library
local://musterbox-defold/musterbox
```

## Initialize

```lua theme={"dark"}
local musterbox = require("musterbox.sdk")

local ok, err = musterbox.create({
  game_id = "my-arena-game",
  game_key = "gk_...",
  environment = "sandbox",
})
assert(ok, err)
assert(musterbox.start())
```

## Authenticate and open a session

```lua theme={"dark"}
local session_id, err = musterbox.authenticate("player@example.com", "secret")
assert(session_id, err)

local ctx, err = musterbox.open_session("sandbox", 1042)
-- ctx.session_id, ctx.token, ctx.context...
```

## Events and polling

```lua theme={"dark"}
musterbox.submit_event("match.start", { mode = "arena" })

-- scheduler helpers for reliable cadence
musterbox.on("wallet", function(evt)
  print("wallet update:", evt)
end)
musterbox.on_error(function(err)
  print("sdk error:", err.code, err.message)
end)

-- per-frame
musterbox.tick(8, 4, 2)
```

## Purchases (Lua)

```lua theme={"dark"}
local pre = musterbox.purchase_request({
  item_id = "item-arena-bundle",
  amount = 9.99,
  purchase_id = "purchase-1",
})
if pre.kind == "Ready" then
  local res, e = musterbox.purchase_verify({
    session_id = pre.session.session_id,
    session_token = pre.session.session_token,
    pin = pin,
    amount = "9.99",
    destination_address = addr,
    idempotency_key = key,
  })
end
```

## Support matrix

| Defold | SDK   | FFI ABI |
| ------ | ----- | ------- |
| 1.6.5+ | 1.0.0 | 1.2.0   |

Next: [Web](/engines/web).
