---
id: I0109
title: "Godot account data decoder"
url: https://carbium.sh/library/integrate/godot-account-data-decoder
collection: Integrations
category: Game engines
revision: 1
updated: 2026-11-23
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Godot account data decoder

A Node relay that keeps your Carbium key, reads one mint account, decodes supply, decimals and authorities from its raw bytes and prints JSON, plus the Godot 4 steps that load that JSON or decode the same bytes in GDScript.

## What a mint account holds

Every SPL token mint is one account on chain, and the `data` field of that account is a fixed run of bytes. A game that wants the supply, the decimals or the mint authority of its in-game currency can read those bytes and decode them itself. The classic Token program lays a mint out in 82 bytes, all little-endian.

| Offset | Size | Field | Type |
|---|---|---|---|
| 0 | 4 | Mint authority tag | u32, 1 when an authority is set |
| 4 | 32 | Mint authority | address |
| 36 | 8 | Supply | u64, raw units |
| 44 | 1 | Decimals | u8 |
| 45 | 1 | Initialized | u8, 1 when ready |
| 46 | 4 | Freeze authority tag | u32, 1 when set |
| 50 | 32 | Freeze authority | address |

A Token-2022 mint starts with the same 82 bytes, is padded to 165 bytes, and then carries an account type byte of 1 at offset 165 followed by its extension data. The decoder reads the first 82 bytes of either kind and leaves the extensions alone. For the extensions themselves see [Token-2022 metadata lookup](https://carbium.sh/library/howsolana/token-2022-metadata-lookup).

A token account is 165 bytes and a wallet's SOL account has no data at all, so the address you pass decides whether the layout fits. The job checks the owner program and the size before it trusts a single offset. The same offset arithmetic for token accounts is in [Token account layout decoder](https://carbium.sh/library/howsolana/token-account-layout-decoder).

## Why the decoding sits on a relay

Godot can call any URL with an `HTTPRequest` node, so a game could ask the [RPC endpoint](https://carbium.sh/docs/endpoints) for the account directly and decode the base64 in GDScript. The catch is the key. An exported project is a `.pck` file that players can unpack, and a key placed in it can be read out. Every key on an account draws on one shared [budget](https://carbium.sh/docs/limits), so a copied key spends what your own services need.

The relay keeps the key in the environment of a process you run. It makes the one read, decodes the bytes and prints a small JSON document. Put the output where your web server can serve it, or call the job from a handler behind your own endpoint and cache the answer for a few seconds. The game then talks to your address and never sees Carbium.

| Field | Meaning |
|---|---|
| address | The account that was read. |
| slot | The slot of the read, as a string. |
| program | The program that owns the account. |
| bytes | The length of the account data. |
| mintAuthority | An address, or null when minting is closed. |
| supply | The raw supply as a string. |
| decimals | Digits after the decimal point. |
| initialized | True when the mint is ready. |
| freezeAuthority | An address, or null. |

A null authority matters to a game economy. A mint with no authority can never create more tokens, which players can check for themselves. A mint whose authority is still set can inflate, and the JSON shows which one you have.

## The Godot side

For the JSON route, add an `HTTPRequest` child to a scene and connect `request_completed`. Call `request("https://your-host/mint.json")` from `_ready`. In the handler check that `response_code` is 200, then hand `body.get_string_from_utf8()` to `JSON.parse_string`. The result is a dictionary with the fields above.

Keep `supply` a string until the last moment. Godot reads every JSON number as a 64-bit float, which drops digits above 2^53, and a token with 9 decimals reaches that size at about nine million units. `String.to_int()` returns a 64-bit integer, so convert there and divide by 10 to the power of `decimals` only for display.

For the raw route, have your server return the base64 string from `data` and decode it in the game. The steps are:

1. Turn the string into bytes with `Marshalls.base64_to_raw(text)` and put them in a `StreamPeerBuffer` through its `data_array` property.
2. `StreamPeerBuffer` reads little-endian by default, which matches the layout, so leave `big_endian` at false.
3. Call `seek(36)` and `get_u64()` for the supply, then `get_u8()` for the decimals, which sits right after it.
4. Call `seek(0)` and `get_u32()` for the authority tag. A value of 1 means the next 32 bytes are the authority, which you read with `get_data(32)`. It returns an array of an error code and the bytes, and you base58 encode the bytes with a small helper of your own.

> Godot integers are signed 64-bit. A supply above 2^63 raw units wraps to a negative number in `get_u64()`, so use the JSON route when the mint is large.

## The job

Install the dependency with `npm install @solana/kit@8.6.0` and set `"type": "module"` in `package.json`. Node 24 strips the types on load. `CARBIUM_KEY` is required and the job exits with a message when it is unset. `CARBIUM_RPC_URL` is optional.

It makes one `getAccountInfo` call with `encoding: "base64"`. The call names no commitment, so kit fills in `confirmed`. The reply carries the slot it was read at, which the job prints so a game can tell how old the numbers are. The base64 text becomes a `Buffer`, a `DataView` reads the integers, and kit's address decoder turns the 32-byte runs into base58 addresses.

`main.ts` (run: `node main.ts <mint>`)

```ts
// I0109 · Godot account data decoder
// https://carbium.sh/library/integrate/godot-account-data-decoder
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import { createDefaultRpcTransport, createSolanaRpcFromTransport, getAddressDecoder, isAddress } from "@solana/kit";

const key = process.env.CARBIUM_KEY;
if (!key) {
  console.error("Set CARBIUM_KEY to your Carbium API key.");
  process.exit(1);
}
// The USDC mint has live traffic; pass your game's mint as the first argument.
const address = process.argv[2] ?? "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
if (!isAddress(address)) {
  console.error("The argument is not an address.");
  process.exit(1);
}

const rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({
    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",
    headers: { "x-api-key": key },
  }),
);

const res = await rpc
  .getAccountInfo(address, { encoding: "base64" })
  .send({ abortSignal: AbortSignal.timeout(10_000) })
  .catch((e: unknown) => {
    console.error("read failed:", e instanceof Error ? e.message : String(e));
    return process.exit(1);
  });
if (!res.value) {
  console.error("account not found");
  process.exit(1);
}

const programs = ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"];
const bytes = Buffer.from(res.value.data[0], "base64");
// 82 bytes is a classic mint; a Token-2022 mint with extensions has account type 1 at byte 165.
const isMint = bytes.length === 82 || (bytes.length > 165 && bytes[165] === 1);
if (!programs.includes(res.value.owner) || !isMint) {
  console.error(`not a token mint: owner ${res.value.owner}, ${bytes.length} bytes`);
  process.exit(1);
}

const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
const addresses = getAddressDecoder();
// COption<Pubkey>: a u32 tag (1 when set), then 32 address bytes.
const option = (at: number) =>
  view.getUint32(at, true) === 1 ? addresses.decode(bytes.subarray(at + 4, at + 36)) : null;

console.log(
  JSON.stringify(
    {
      address,
      slot: res.context.slot.toString(),
      program: res.value.owner,
      bytes: bytes.length,
      mintAuthority: option(0),
      supply: view.getBigUint64(36, true).toString(),
      decimals: bytes[44],
      initialized: bytes[45] === 1,
      freezeAuthority: option(46),
    },
    null,
    1,
  ),
);
```

Run it with `node main.ts <mint>`. With no argument it reads the USDC mint, which has plenty of recent traffic. The JSON goes to stdout and every problem to stderr with exit status 1, so `node main.ts > next.json && mv next.json mint.json` never replaces a good file with a bad one.

## What a refresh costs

A run is one account read, and account reads cost 10 cells each. A Free key is rated at 0.5 req/s for that class, so one run every two seconds is the most it sustains, while Dev takes 15, Business 50 and Pro 400 req/s.

A mint changes slowly. Refreshing every minute keeps a game's currency page current, costs 10 cells a minute and stays the same whether ten players or ten thousand open the file. Decode several mints by running the job once per address; the 429 response and its retry hint are in [errors](https://carbium.sh/docs/errors).

## Where it ends

- It decodes mint accounts only. Metaplex metadata, token accounts and your own game program's accounts each have their own layout, and an Anchor account starts with an 8-byte discriminator that this job does not read.
- Token-2022 extension data after byte 165 is left undecoded. The job reports the base mint fields and the total length.
- The read is one snapshot at `confirmed`. A supply that changes a moment later shows up on the next run, and the printed slot says which snapshot you have.
- A plain SOL wallet has no data to decode. Its balance comes from `getBalance`, and a live change to it arrives through `logsSubscribe` mentions, because [accountSubscribe](https://carbium.sh/docs/websocket) sends nothing for a plain SOL wallet.
- The job never signs or sends. Minting and burning score tokens stay in your own server code.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The job prints `not a token mint` for an address you expected to work. | The account is not owned by the Token program or Token-2022, or its size does not match a mint. A token account has 165 bytes. Pass the token's mint address. A holder's address points at a token account. |
| The log shows `read failed` with `HTTP error (401)`. | The key was refused as unknown. Check that `CARBIUM_KEY` holds the whole key and that the process running the job receives it. |
| The log shows `read failed` with `HTTP error (429)`. | The account is over its rate for account reads. Run the job less often, cache its output, and check that no other key on the account is using the same budget. The previous file stays in place. |
| The job prints `account not found`. | The address holds no account on mainnet. Check for a typo and for an address copied from another cluster. |
| The supply shown in Godot has wrong last digits or a negative sign. | The value passed through a JSON number or `get_u64()` past 2^63. Keep `supply` a string in the JSON and convert it with `String.to_int()` only for values that fit. |
| The authority fields decode to a long unreadable string or a wrong address. | The tag at the front of each authority was skipped. Authorities start 4 bytes after their tag, at offsets 4 and 50, and each is 32 bytes. |

## Questions

### Can the game decode a Token-2022 mint with this layout?

Yes for the first 82 bytes, which are identical. Extensions such as transfer fees or metadata follow byte 165 and need their own decoders.

### Why print the slot?

A read is a snapshot. The slot lets a game compare two files and keep the newer one, and lets you tell a stale cache from a fresh read.

### Can the relay decode accounts from my own game program?

Yes. Change the offsets and the owner check to match your program's layout. If the program uses Anchor, skip the 8-byte discriminator at the front first.

### Does the player's wallet need to be connected for this?

No. The job reads public account data with your key, so the game can show supply and authorities before a player signs in. Connecting a wallet matters for reading that player's balance, which is [SPL token balance](https://carbium.sh/library/howsolana/spl-token-balance).

## Related

- [Token account layout decoder](https://carbium.sh/library/howsolana/token-account-layout-decoder) (How to use Solana, HS0021)
- [Godot on-chain leaderboard](https://carbium.sh/library/integrate/godot-on-chain-leaderboard) (Integrations, I0041)
- [carbium.sh/docs/endpoints](https://carbium.sh/docs/endpoints)
- [carbium.sh/docs/rpc](https://carbium.sh/docs/rpc)
- [carbium.sh/docs/limits](https://carbium.sh/docs/limits)
- [carbium.sh/docs/errors](https://carbium.sh/docs/errors)
- [carbium.sh/docs/websocket](https://carbium.sh/docs/websocket)
