Load a 3D Chonk

Fetch any Chonk from the Chonks indexer and render it in three.js or any other 3D engine, with its Traits layered in the right order.

What is this?

Every Chonk is a voxel model stored on-chain on Base. The body and each equipped Trait are lists of colored voxels on the same grid.
The Chonks indexer serves a ready-to-render model for any Chonk. One GET request gives you the voxels with the Traits already layered, so you only need to draw cubes.
This page tells you, or the agent writing your code, how to fetch a Chonk, what the data means, and how to put it in a scene. If you want a Chonk that walks, waves, and jumps, skip to Rig And Animate With RigKit.

Quick Start

const res = await fetch("https://indexer.chonks.xyz/chonk/27543/3d");
const { success, chonk, error } = await res.json();
if (!success) throw new Error(error);

for (const { x, y, z, color } of chonk.voxels) {
  // Draw one 1×1×1 cube at (x, y, z) in `color`.
  // See Coordinates for how to place it in your world.
}
That is the whole integration. The rest of this page explains the fields and the conventions.

Get A 3D Chonk

GET https://indexer.chonks.xyz/chonk/:chonkId/3d
curl https://indexer.chonks.xyz/chonk/27543/3d
  • No API key and no wallet
  • chonkId is the decimal token ID, such as 27543
  • The response is JSON
{
  "success": true,
  "chonk": {
    "tokenId": 27543,
    "owner": "0x…",
    "layerOrder": ["body", "shoes", "bottom", "top", "hair", "face", "head", "accessory"],
    "traits": [
      { "layer": "shoes", "name": "Shoes White" },
      { "layer": "bottom", "name": "Suspender Shorts Black" },
      { "layer": "top", "name": "Lost Sweater Dark" },
      { "layer": "face", "name": "Shades" },
      { "layer": "head", "name": "Baseball Cap Black" },
      { "layer": "accessory", "name": "Red Balloon" }
    ],
    "accessory": "Red Balloon",
    "bodyIndex": 2,
    "backgroundColor": "7b939d",
    "zMap": "0b1705ba8136…",
    "voxelCount": 534,
    "voxels": [
      { "x": 11, "y": 23, "z": 5, "color": "#ffffff" },
      …
    ],
    "bounds": {
      "min": { "x": 9, "y": 6, "z": 3 },
      "max": { "x": 26, "y": 23, "z": 8 }
    },
    "updatedAtBlock": 37916337
  }
}

Response Fields

  • voxels: what you draw. One entry per visible cell. color is #rrggbb, ready for new THREE.Color(color) or any CSS-style color parser
  • voxelCount: the length of voxels
  • bounds: the smallest and largest x, y and z in voxels. Use it to center the model or fit the camera
  • zMap: the same model as one hex string, in layer order, before layering is applied. Pass it to tools that take a zMap, such as RigKit. See The zMap Format
  • layerOrder: the layers from bottom to top. It is always the same eight values
  • traits: the equipped Traits, in layerOrder. An empty slot is left out, so a Chonk with no hat has no head entry
  • accessory: the Accessory Trait name, or null. RigKit uses it to keep a hand on a held item
  • bodyIndex: the skin tone, 0 to 4
  • backgroundColor: the Chonk's background color as 6 hex characters with no #. Useful for a matching scene background
  • owner: the current owner, EIP-55 checksummed
  • updatedAtBlock: the Base block the Traits in the model were last read at

Errors

Errors use one shape:
{ "success": false, "code": "NOT_FOUND", "error": "The indexer has no 3D model for Chonk #999999." }
  • INVALID_CHONK_ID (HTTP 400): the ID is not a decimal number
  • NOT_FOUND (HTTP 404): no Chonk has that ID
  • QUERY_FAILED (HTTP 500): the indexer had a problem. Retry after a short wait
Branch on code, not on the error text.

What Is Already Done For You

The endpoint does this work before it responds, so your code does not have to:
  • Layering. Traits are applied in render order. Where a Trait covers the body or a lower Trait, only the outer voxel is in voxels. About a quarter of a dressed Chonk's raw voxels are hidden this way
  • Normalizing. zMap is plain lowercase hex with no 0x. You never need to decode hex-encoded ASCII
  • Body tone. The body layer always matches bodyIndex, including after an owner changes skin tone
  • Trait names. traits and accessory come from the Chonk's metadata, so you do not need to decode the tokenURI
  • No chain reads. Everything comes from the indexer. You do not need an RPC endpoint or a wallet
What you still do yourself: build the mesh, place it in your world, light it, and animate it if you want to.

The zMap Format

A zMap is a hex string. Every 12 hex characters (6 bytes) is one voxel:
0b 17 05 ef b1 5e
x  y  z  r  g  b
  • x, y, z: one byte each, the grid cell
  • r, g, b: one byte each, the color. The example voxel is #efb15e at x = 11, y = 23, z = 5
To parse it yourself:
function parseZMap(zMap: string) {
  const cells = new Map<string, { x: number; y: number; z: number; color: string }>();
  for (let i = 0; i + 12 <= zMap.length; i += 12) {
    const x = parseInt(zMap.slice(i, i + 2), 16);
    const y = parseInt(zMap.slice(i + 2, i + 4), 16);
    const z = parseInt(zMap.slice(i + 4, i + 6), 16);
    const color = `#${zMap.slice(i + 6, i + 12)}`;
    cells.set(`${x},${y},${z}`, { x, y, z, color }); // a later voxel replaces an earlier one
  }
  return [...cells.values()];
}
You only need this if you take zMap instead of voxels, or read a zMap from somewhere else. The parser must let a later voxel replace an earlier one in the same cell. If it keeps the first voxel instead, the body shows through clothes.

Layer Order

The zMap lists the layers bottom first, in the same order as the on-chain renderer and the 2D art:
  1. Body
  2. Shoes
  3. Bottom
  4. Top
  5. Hair
  6. Face
  7. Head
  8. Accessory
Each voxel has its own x, y, z, so order only matters when two layers fill the same cell. Then the later layer wins: a Top covers the body, and a Head item covers Hair. voxels already has this applied.

Coordinates

The grid is 30 × 30 cells across and high, and a few cells deep.
  • x runs left to right as you look at the Chonk's face. The middle column is x = 14
  • y runs top to bottom. The feet are on row y = 23
  • z runs back to front. A larger z is nearer the front, where the face is
Most engines have Y pointing up, so flip y. To stand the Chonk on the ground at the origin, facing +Z, with 1-unit cubes:
const position = {
  x: voxel.x - 14.5,
  y: 23 - voxel.y + 0.5,
  z: voxel.z - 5.5,
};
The + 0.5 puts each cube's center inside its cell, so the soles sit on y = 0. Scale the whole model afterward. RigKit uses 0.075 world units per voxel, which makes a Chonk about 1.8 units tall.

Render In three.js

This builds one merged mesh and skips every face that touches another voxel. One mesh draws fast, and no lines show between cubes.
import * as THREE from "three";

const FACES = [
  { n: [1, 0, 0], c: [[1, 0, 0], [1, 1, 0], [1, 1, 1], [1, 0, 1]] },
  { n: [-1, 0, 0], c: [[0, 0, 1], [0, 1, 1], [0, 1, 0], [0, 0, 0]] },
  { n: [0, 1, 0], c: [[0, 1, 1], [1, 1, 1], [1, 1, 0], [0, 1, 0]] },
  { n: [0, -1, 0], c: [[0, 0, 0], [1, 0, 0], [1, 0, 1], [0, 0, 1]] },
  { n: [0, 0, 1], c: [[1, 0, 1], [1, 1, 1], [0, 1, 1], [0, 0, 1]] },
  { n: [0, 0, -1], c: [[0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0]] },
];

export async function loadChonkMesh(chonkId: number, voxelSize = 0.075) {
  const res = await fetch(`https://indexer.chonks.xyz/chonk/${chonkId}/3d`);
  const { success, chonk, error } = await res.json();
  if (!success) throw new Error(error);

  // World cells: x right, y up, z toward the viewer.
  const cells = chonk.voxels.map((v) => ({
    x: v.x - 15,
    y: 23 - v.y,
    z: v.z - 6,
    color: new THREE.Color(v.color),
  }));
  const filled = new Set(cells.map((c) => `${c.x},${c.y},${c.z}`));

  const positions: number[] = [];
  const normals: number[] = [];
  const colors: number[] = [];
  const indices: number[] = [];

  for (const cell of cells) {
    for (const face of FACES) {
      const [nx, ny, nz] = face.n;
      if (filled.has(`${cell.x + nx},${cell.y + ny},${cell.z + nz}`)) continue;
      const start = positions.length / 3;
      for (const [cx, cy, cz] of face.c) {
        positions.push(cell.x + cx, cell.y + cy, cell.z + cz);
        normals.push(nx, ny, nz);
        colors.push(cell.color.r, cell.color.g, cell.color.b);
      }
      indices.push(start, start + 1, start + 2, start, start + 2, start + 3);
    }
  }

  const geometry = new THREE.BufferGeometry();
  geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
  geometry.setAttribute("normal", new THREE.Float32BufferAttribute(normals, 3));
  geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
  geometry.setIndex(indices);

  const mesh = new THREE.Mesh(geometry, new THREE.MeshStandardMaterial({ vertexColors: true }));
  mesh.scale.setScalar(voxelSize);
  return { mesh, chonk };
}
Here each cell's corner is at the integer position, so the cube spans x to x + 1. The Chonk stands on y = 0, centered on x = 0, and faces +Z. Point a camera at it from +Z.
For a quick test, an InstancedMesh of BoxGeometry with one instance per voxel also works. It is simpler, but thin lines can show between cubes.

Other 3D Engines

The data is engine-agnostic. In any engine:
  1. GET /chonk/:chonkId/3d
  2. For each entry in voxels, place a unit cube using the mapping in Coordinates. Flip y if your engine's Y points up. Swap axes if your engine is Z-up
  3. Color each cube from color
  4. Merge the cubes into one mesh and drop faces between neighbors if the engine does not do it for you
Notes per engine:
  • Babylon.js: build a Mesh from VertexData with the same face loop as the three.js example. Babylon is left-handed, so negate z. Negating one axis mirrors the mesh and turns the faces inside out, so also reverse the order of each face's corners
  • Unity: Y is up and the coordinates are left-handed. Negate z so the Chonk faces a default camera, and reverse the order of each face's corners for the same reason as Babylon. Build one Mesh with vertex colors
  • Godot: Y is up, right-handed like three.js. Build an ArrayMesh with SurfaceTool and vertex colors
  • Blender, MagicaVoxel and other tools: convert voxels to the tool's voxel format, or export the three.js mesh with GLTFExporter to a .glb and import that
  • Game engines that load glTF: export once with GLTFExporter and load the .glb like any other model

Rig And Animate With RigKit

RigKit (rigkit-threejs on npm) turns a zMap into a rigged, animated Chonk for three.js. It is the Chonk from the Chonks Playground, with no React or wallet code. Its only dependency is three.
npm install rigkit-threejs three
import * as THREE from "three";
import { ChonkRig, ChonkAnimator } from "rigkit-threejs";

const res = await fetch("https://indexer.chonks.xyz/chonk/27543/3d");
const { chonk } = await res.json();

const rig = new ChonkRig({ zMap: chonk.zMap, accessory: chonk.accessory });
scene.add(rig.object);

const animator = new ChonkAnimator(rig);
animator.play("walk"); // "idle" | "walk" | "run" | "jump" | "wave" | "bow"

const timer = new THREE.Timer();
renderer.setAnimationLoop((time) => {
  timer.update(time);
  animator.update(timer.getDelta());
  renderer.render(scene, camera);
});
What RigKit does:
  • Splits the voxels into bones: torso, body, both arms, both legs and both feet
  • Keeps an arm still when the Accessory is held in that hand, such as a balloon or a sword. Pass accessory for this
  • Faces +Z, stands on y = 0, and is about 1.8 units tall at the default voxelSize of 0.075
  • Includes BASE_BODIES in rigkit-threejs/bodies, the five bare bodies, so you can show a Chonk with no network request
RigKit also has fetchChonk(tokenId), which reads the older /chonk/zmap endpoint. Prefer passing chonk.zMap from /chonk/:chonkId/3d, because that zMap is normalized and its body always matches bodyIndex.
The animations do not move the Chonk through the world. Move rig.object yourself, and play "jump" while your code lifts it. Read the RigKit README for the bone names, posing, and a React Three Fiber example.

Other Endpoints

  • GET /chonk/owner/:address: the Chonks a wallet owns. Use the id of each row with /chonk/:chonkId/3d
  • GET /chonk/:chonkId/traits: one row per Trait in the Chonk's Backpack, with that Trait's own zMap, colorMap and animationData3d. Use it to draw a single Trait or to animate Traits that move in 3D. A Trait's own zMap can be hex-encoded ASCII, so decode it before parsing
  • GET /chonk/zmap?tokenId=1&tokenId=2: the raw stored zMaps for several Chonks in one request. These are not normalized or layered, so prefer /chonk/:chonkId/3d for rendering
All of them are on https://indexer.chonks.xyz.

Agent Checklist

If you are an agent building this for a user:
  • Ask the user which Chonk IDs to show. Do not walk ID ranges
  • Use /chonk/:chonkId/3d and draw voxels. Do not re-implement layering
  • Flip y. The grid's y grows downward
  • Merge cubes into one mesh for anything beyond a quick test
  • Cache the response per Chonk. A model only changes when its owner changes Traits or skin tone
  • Do not read the chain or ask the user for an RPC key. The indexer has everything
  • For a walking or animated Chonk in three.js, use RigKit