Skip to main content

TypeScript Support

This package includes full TypeScript definitions! No need for @ts-ignore or type assertions.
import {
  X404Blacklist,
  X404TimeLock,
  X404MultiToken,
  X404Activity,
  X404Tier,
  X404NoDebt,
  X404Age,
} from "magenx404";
import { detectWallets, getGeolocationData } from "magenx404/utils";

// Full type safety and IntelliSense support!
const wallets = detectWallets(); // string[]
const location = await getGeolocationData(); // Promise<GeolocationData>
const result = await X404TimeLock({ ... }); // Promise<X404Result>

Basic Usage with Types

import { X404Blacklist } from "magenx404";

const result = await X404Blacklist({
  excluded_mints: ["scam_token_address"],
  max_holdings: {},
  geo_code: "false",
  geo_code_locs: "",
  coords: { latitude: null, longitude: null },
});

if (result.success) {
  console.log("Token:", result.token);
} else {
  console.error("Error:", result.error);
}

Type-Safe Error Handling

import { X404Blacklist } from "magenx404";

async function authenticate(): Promise<void> {
  const result = await X404Blacklist({
    excluded_mints: ["token_address"],
    max_holdings: {},
    geo_code: "false",
    geo_code_locs: "",
    coords: { latitude: null, longitude: null },
  });

  if (!result.success) {
    switch (result.error) {
      case "HOLDS_BANNED_TOKEN":
        console.error("User holds banned token");
        break;
      case "EXCEEDS_MAX_HOLDING":
        console.error("User exceeds max holding");
        break;
      case "WALLET_CANCELLED":
        console.error("User cancelled wallet selection");
        break;
      case "LOCATION_DENIED":
        console.error("Access denied for your location");
        break;
      case "LOCATION_ERROR":
        console.error("Location permission denied");
        break;
      default:
        console.error("Unknown error:", result.error);
    }
    return;
  }

  // TypeScript knows result.token exists here
  console.log("Authenticated! Token:", result.token);
}

Multiple Features with Union Types

import { X404Blacklist, X404TimeLock, X404Tier } from "magenx404";

async function authenticate(
  feature: "blacklist" | "timelock" | "tier",
  config: any
) {
  switch (feature) {
    case "blacklist":
      return await X404Blacklist(config);
    case "timelock":
      return await X404TimeLock(config);
    case "tier":
      return await X404Tier(config);
  }
}