Skip to content

Magic: The Gathering card data ​

Ruleset and calculator scripts get Magic: The Gathering cards as plain objects straight from the card catalog. The data comes from Scryfall and covers paper Magic. This page lists every field on those objects and in the catalog globals, with a real example and a few recipes.

Where the cards show up:

  • Card rules receive one card as their first argument.
  • Deck and deck set rules receive cardsById, an object keyed by card ref that holds every card in the deck (it can hold more).
  • Calculators receive cardsById as their second argument.

See the ruleset script API and the calculator script API for the full function signatures.

Card keys and deck refs ​

A Magic card in the catalog is a card identity: one playable card with all of its printings (reprints, promos, Secret Lair and The List versions) listed under printings. Two ids matter:

  • The identity id, card.id: mtg- plus a hash, like mtg-7cc37a2f416de612a410.
  • A printing id: <set code>-<collector number>, like eld-115 or clb-781. A few printings with unusual collector numbers get a longer id, such as plst-ELD11524d6.

Decks store printing ids, so a deck is a map like { "eld-115": 2, "clb-781": 2 }. cardsById is keyed by those same printing ids, and each one points to its identity. In that example both refs are Bonecrusher Giant, so cardsById["eld-115"] and cardsById["clb-781"] are the same card and share one card.id:

  • Count copies of "the same card" by card.id (or card.name), not by ref. The deck above runs 4 Bonecrusher Giant.
  • To read the printing a ref points to, find it in the list: card.printings.find((p) => p.id === ref).
  • ctx.globals.printings[ref] gives the identity id for any printing id, when globals are available.

A card rule gets the identity card itself, so card.id is always the identity id, never a printing id.

The game fields describe the card's default printing, the first entry of printings (game.defaultPrintingId). That matters for the per-printing fields rarity, collectorNumber and releasedAt, and for card.setCode.

Guard against a missing card before reading from it: cardsById[ref] can be undefined when the catalog doesn't know a ref.

Card fields ​

Every card, in every game, has these top-level fields:

PropertyTypeDescription
idstringCatalog id of the card identity ("01DE012" in LoR, "pikachu-ex--1f29b66b68bc" in Pokémon).
slug?stringThe card's public URL segment (#2189, ADL §64): a frozen English slug, identical in every locale. Equals id for a game whose readable slugs are off (readableCardSlugsEnabled in @turny/game-adapters) or a card that has no readable slug yet. Pokémon keeps its <name>--<hash12> id as its slug; LoR's switch stays off for good, so its URLs stay its card codes. A page whose route param already equals slug renders; any other known key (the id, a history slug, an alias) redirects to it, so a card whose slug equals its id never redirects to itself.

The catalog export (#2193) writes it only for a switched-on game and only when it differs from id, so an absent slug means the id: always read it through cardSlugOf (@turny/game-adapters).
namestringDisplay name in the catalog locale.
setCodestringSet of the card, or of its default printing ("set1", "sv2", "OGN").
collectible?booleanFalse for cards that can't go in a deck (LoR tokens and level-ups).
assets?CardCatalogCardAssetContract[]Images of the card's default printing.
printings?CardPrintingContract[]Every printing of the identity, default printing first (only some on a partial card, see partialPrintings). Absent in LoR.
printingCount?numberLean list files (#1323), which omit printings, partial cards (see partialPrintings) and per-identity core files (#1522): how many printings the full card has. Absent on full cards and in games without printings.
printingSetCodes?string[]Lean list files (#1323), partial cards and per-identity core files: the distinct set codes across the full card's printings, in printing order. Absent on full cards.
printingsFile?stringPer-identity core files (#1522) only: the card's printings file (identities/<id>.printings.<hash8>.json, relative to the locale directory, see cardCatalogIdentityPrintingsFileName), in place of printings. Absent when the printings are inline in the core file.
partialPrintings?booleanTrue on a partial card (the featured-cards bundle, #1330): printings holds only some of the identity's printings (its default printing plus the ones the featured content references), while printingCount / printingSetCodes summarize all of them. Absent on full and list cards.
hasImage?booleanFalse when none of the card's printings has an image in this language. Absent means it has one.
languages?CardLanguageEntry[]Catalog locales that hold real text for this card (#2552). A locale whose entry is only fallback text is absent. Absent on older exports and in single-locale games.
game?TGameDataGame-specific fields; see the per-game *CardGameData type.

Each entry of languages (CardLanguageEntry):

PropertyTypeDescription
localestringCatalog locale ("zh-tw", "de_de"), not an app locale.
statusCardLanguageStatusWhere the text comes from: official (printed) or unofficial (a translation).

Values of a language entry's status (CardLanguageStatus):

MemberValueDescription
Official"official"Printed in this language by the publisher.
Unofficial"unofficial"Real text the publisher did not print in this language: a reconstruction or a translation.

Printings ​

Each entry of printings (CardPrintingContract):

PropertyTypeDescription
idstringPrinting id; deck refs use it ("sv2-11" for Pokémon, "ogn-030-298" for Riftbound).
setCodestringSet the printing belongs to ("sv2", "OGN").
number?stringCollector number within the set.
language?stringLanguage of the printing, when it is not the catalog's own.
releaseDate?stringRelease date as the source gives it ("2023/06/09").
assets?CardCatalogCardAssetContract[]This printing's own images.
variants?CardVariantContract[]Treatments of this printing (foil, alternate art, …).
metadata?JsonObjectExtra per-printing data (rarity, artist, store ids); game-specific.

Each entry of a printing's variants:

PropertyTypeDescription
idstringVariant id, usually <printing id>:<kind> ("ogn-030-298:normal").
kind?stringTreatment kind ("normal", "foil", "alternate_art"); values are per game.
label?stringDisplay label, when the kind alone is not enough.
metadata?JsonObjectExtra per-variant data; game-specific.

Each entry of assets (on the card and on each printing):

PropertyTypeDescription
kindCardAssetKindWhat the image shows: "card" (framed render), "full" (full art), "icon", "banner", "slice", "portrait", …
urlstringImage URL.
format?CardAssetFormatImage format ("webp"), when known.
width?numberWidth in pixels, when known.
height?numberHeight in pixels, when known.
metadata?JsonObjectExtra per-asset data; game-specific.

Game fields (card.game) ​

Everything specific to Magic lives on card.game. Values follow Scryfall: colors are the letters W U B R G, costs use brace notation ({2}{W}{W}), and rarity and legality are lower-case tokens you can compare directly.

Watch for three things:

  • Colorless means missing. A colorless card has no colors (and a colorless identity has no colorIdentity); there is no C color. Read them as game.colors || [].
  • power, toughness, loyalty and defense are strings, as printed ("4", "*", "1+*"). Convert with Number() and check for NaN before doing math.
  • Cards with more than one face (double-faced, split, adventure and flip cards) keep their rules text on faces, not on oracleText. Double-faced cards also keep their mana cost and colors only on faces. Read both when you need a card's text or cost.
PropertyTypeDescription
manaCost?stringMana cost in Scryfall's brace notation ("{2}{W}{W}"). Split, adventure and flip cards join their halves' costs with " // "; double-faced cards have it only on faces. Absent on lands.
cmc?numberMana value (converted mana cost), such as 4. 0 for lands.
colors?MtgColor[]Colors as WUBRG letters (["W", "U"]). Absent on colorless cards, and on double-faced cards, whose colors are on faces.
colorIdentity?MtgColor[]Color identity as WUBRG letters: the colors in the cost and rules text, as Commander uses them. Absent when colorless.
typeLine?stringType line ("Legendary Creature — Elf Druid"). A multi-face card joins its faces' lines with " // ".
oracleText?stringRules (Oracle) text. On a multi-face card it is on faces instead.
englishName?stringThe card's English name, on a card whose name is translated ("Lightning Bolt" in a catalog that names it "稲妻"). Deck lists, imports and English search use it. Absent in English and on untranslated cards.
printedTypeLine?stringType line as printed in the catalog's language ("Éphémère"). Display only: rules, filters and deck checks read the English typeLine. Absent in English and on untranslated cards.
printedText?stringRules text as printed in the catalog's language. Display only: rules read the English oracleText. Absent in English and on untranslated cards.
flavorText?stringFlavor text.
keywords?string[]Keyword abilities and actions, as Scryfall names them (["Flying", "First strike"]).
rarity?MtgRarityRarity of the default printing: "common", "uncommon", "rare", "mythic", "special" or "bonus".
power?stringPower, as printed ("4", "*", "1+*"). Convert with Number() before doing math.
toughness?stringToughness, as printed.
loyalty?stringPlaneswalker starting loyalty, as printed ("4", "X").
defense?stringBattle starting defense, as printed ("5").
legalities?MtgCardLegalitiesLegality per format, keyed by Scryfall format id ({ modern: "legal", standard: "not_legal" }), plus Turny's standard_future key. Values are "legal", "not_legal", "restricted" or "banned".
isProvisional?booleanTrue while the card is announced but not yet released: none of its printings has a released_at on or before the catalog's generation time. Scryfall marks such a card not_legal in every format until release day; legalities.standard_future is legal meanwhile when it is bound for a Standard set. Absent once any printing has released.
faces?MtgCardFaceContract[]One entry per face of a double-faced, split, adventure or flip card. Absent on single-faced cards.
layout?stringScryfall's layout: "normal", "transform", "modal_dfc", "split", "adventure", "flip", "saga", …
associatedCardRefs?string[]Printing ids of related cards, such as the tokens it makes or its meld partner.
collectorNumber?stringCollector number of the default printing within its set ("115").
releasedAt?stringRelease date of the default printing ("2019-10-04").
defaultPrintingId?stringId of the default printing ("eld-115"): the newest regular booster printing, at its lowest rarity. Always the first entry of printings; deck rows and card art default to it.
oracleId?stringScryfall's stable oracle identity id, shared by every printing.

Faces ​

Each entry of faces:

PropertyTypeDescription
namestringThis face's name ("Stomp").
manaCost?stringThis face's mana cost ("{1}{R}"). Absent on a back face that is never cast.
typeLine?stringThis face's type line ("Instant — Adventure").
oracleText?stringThis face's rules text.
printedTypeLine?stringThis face's type line as printed in the catalog's language ("Créature — humain et chevalier"). Display only: rules and filters read the English typeLine. Absent in English and on untranslated cards.
printedText?stringThis face's rules text as printed in the catalog's language. Display only: rules read the English oracleText. Absent in English and on untranslated cards.
flavorText?stringThis face's flavor text.
colors?MtgColor[]This face's colors as WUBRG letters, on double-faced cards (Scryfall lists other cards' colors once, at the top).
power?stringThis face's power, as printed ("4", "*").
toughness?stringThis face's toughness, as printed.
loyalty?stringThis face's starting loyalty, as printed.
defense?stringThis face's starting defense (a battle face), as printed.

Globals (ctx.globals) ​

The catalog's globals hold set names and the printing index that maps every printing id to its identity.

When globals are available

Globals are passed to ruleset scripts as ctx.globals (the last argument). Calculators may not receive ctx at all, and a ruleset can run without it too. Always check ctx && ctx.globals before using them.

PropertyTypeDescription
printings?Record<string, string>Printing id → owning card identity id, for every printing ("eld-115" → "mtg-7cc37a2f416de612a410"). Deck refs are printing ids, so this is how a ref finds its card.
sets?Record<string, MtgCatalogSetLookupEntry>Sets by the card's setCode ("eld" → Throne of Eldraine).

Set entries ​

Each entry of sets:

PropertyTypeDescription
labelstringThe set's name ("Throne of Eldraine").
type?stringScryfall's set type: "core", "expansion", "masters", "commander", …
releasedAt?stringThe set's release date ("2019-10-04"): the earliest released_at of its printings. Ranks sets for the daily card puzzle's set column (#1370).

Example card ​

Bonecrusher Giant, an adventure card, trimmed to two printings with images and most format legalities left out:

json
{
  "id": "mtg-7cc37a2f416de612a410",
  "name": "Bonecrusher Giant // Stomp",
  "setCode": "eld",
  "collectible": true,
  "printings": [
    {
      "id": "eld-115",
      "setCode": "eld",
      "number": "115",
      "releaseDate": "2019-10-04",
      "metadata": {
        "scryfallId": "09fd2d9c-1793-4beb-a3fb-7a869f660cd4",
        "rarity": "rare"
      }
    },
    {
      "id": "clb-781",
      "setCode": "clb",
      "number": "781",
      "releaseDate": "2022-06-10",
      "metadata": {
        "scryfallId": "b5b71cd2-de35-451f-b16e-2e3936169407",
        "rarity": "rare"
      }
    }
  ],
  "hasImage": true,
  "game": {
    "manaCost": "{2}{R} // {1}{R}",
    "cmc": 3,
    "colors": ["R"],
    "colorIdentity": ["R"],
    "typeLine": "Creature — Giant // Instant — Adventure",
    "flavorText": "Not every tale ends in glory.",
    "rarity": "rare",
    "power": "4",
    "toughness": "3",
    "legalities": {
      "standard": "not_legal",
      "standard_future": "not_legal",
      "pioneer": "legal",
      "modern": "legal",
      "legacy": "legal",
      "vintage": "legal",
      "pauper": "not_legal",
      "commander": "legal"
    },
    "faces": [
      {
        "name": "Bonecrusher Giant",
        "manaCost": "{2}{R}",
        "typeLine": "Creature — Giant",
        "oracleText": "Whenever this creature becomes the target of a spell, this creature deals 2 damage to that spell's controller.",
        "flavorText": "Not every tale ends in glory.",
        "power": "4",
        "toughness": "3"
      },
      {
        "name": "Stomp",
        "manaCost": "{1}{R}",
        "typeLine": "Instant — Adventure",
        "oracleText": "Damage can't be prevented this turn. Stomp deals 2 damage to any target."
      }
    ],
    "layout": "adventure",
    "associatedCardRefs": ["teld-20", "eld-291"],
    "collectorNumber": "115",
    "releasedAt": "2019-10-04",
    "oracleId": "d6d72f5f-8f5d-4180-b514-f22ff5482902",
    "defaultPrintingId": "eld-115"
  }
}

Common recipes ​

js
// Calculator: cards per type. Each card counts once, toward the first type
// on its type line from this list, so artifact creatures count as creatures.
export default function compute(pile, cardsById) {
  const order = [
    "Creature",
    "Planeswalker",
    "Battle",
    "Instant",
    "Sorcery",
    "Artifact",
    "Enchantment",
    "Land",
  ];
  const counts = {};

  Object.keys(pile).forEach((ref) => {
    const game = (cardsById[ref] && cardsById[ref].game) || {};
    const typeLine = game.typeLine || "";
    const type = order.find((name) => typeLine.indexOf(name) !== -1) || "Other";

    counts[type] = (counts[type] || 0) + pile[ref];
  });

  return {
    widgets: [
      {
        kind: "donut",
        label: "Card types",
        segments: Object.keys(counts).map((type) => ({
          label: type,
          value: counts[type],
        })),
      },
    ],
  };
}
js
// Calculator: nonland copies at each mana value, 7+ grouped.
export default function compute(pile, cardsById) {
  const buckets = [0, 0, 0, 0, 0, 0, 0, 0];

  Object.keys(pile).forEach((ref) => {
    const game = (cardsById[ref] && cardsById[ref].game) || {};

    if ((game.typeLine || "").indexOf("Land") !== -1) {
      return; // Lands sit at 0 and would swamp the curve.
    }

    const cmc = typeof game.cmc === "number" ? game.cmc : 0;

    buckets[Math.min(Math.floor(cmc), 7)] += pile[ref];
  });

  return {
    widgets: [
      {
        kind: "histogram",
        label: "Mana curve",
        buckets: buckets,
        labels: ["0", "1", "2", "3", "4", "5", "6", "7+"],
      },
    ],
  };
}
js
// Card rule: legal in Modern. Restricted, banned and not_legal all fail.
export default function validateCard(card) {
  const legalities = (card.game && card.game.legalities) || {};

  if (legalities.modern === "legal") {
    return true;
  }

  return {
    valid: false,
    issues: [{ message: card.name + " is not legal in Modern." }],
  };
}
js
// Card rule: fits a white-blue Commander deck. Colorless cards always fit.
export default function validateCard(card) {
  const identity = (card.game && card.game.colorIdentity) || [];
  const allowed = ["W", "U"];
  const outside = identity.filter((color) => allowed.indexOf(color) === -1);

  if (outside.length === 0) {
    return true;
  }

  return {
    valid: false,
    issues: [
      { message: card.name + " has " + outside.join("") + " in its identity." },
    ],
  };
}
js
// Card rule: only cards whose default printing is from Throne of Eldraine.
// Uses the set's name from the globals when they exist.
export default function validateCard(card, ctx) {
  if (card.setCode === "eld") {
    return true;
  }

  const globals = ctx && ctx.globals;
  const set =
    globals && globals.sets && globals.sets.eld
      ? globals.sets.eld.label
      : "eld";

  return {
    valid: false,
    issues: [{ message: card.name + " is not from " + set + "." }],
  };
}

Turny.gg documentation