Skip to content

SDK Examples

This guide provides practical examples of common operations using Atom Core’s SDK.

Basic Setup

import { createAtom } from "@hexon-studio/atom-core";
import { PublicKey } from "@solana/web3.js";
// Initialize SDK
const api = createAtom({
rpcUrl: "https://api.mainnet-beta.solana.com",
playerProfile: new PublicKey("your_profile_address"),
owner: new PublicKey("your_wallet_address"),
keypair: "your_keypair"
});
// Initialize the API
await api.init();
// Clean up when done
await api.dispose();

Fleet Operations

Dock a Fleet

const { status, data, error } = await api.fleet.dock("FleetName123");
if (status === "error") {
console.error("Failed to dock:", error);
return;
}
console.log("Fleet docked successfully:", data);

Start Mining

const { status, data, error } = await api.fleet.startMining({
fleet: "FleetName123",
resource: "ResourceMint123"
});
if (status === "error") {
console.error("Failed to start mining:", error);
return;
}
console.log("Mining started:", data);

Load Cargo

const { status, data, error } = await api.fleet.loadCargo({
fleet: "FleetName123",
items: [{
resourceMint: new PublicKey("ResourceMint123"),
mode: "fixed",
amount: 100,
cargoPodKind: "fuel_tank"
}]
});
if (status === "error") {
console.error("Failed to load cargo:", error);
return;
}
console.log("Cargo loaded:", data);

Crafting Operations

Start Crafting

const { status, data, error } = await api.starbase.startCrafting({
crew: 10,
starbase: "Starbase123",
quantity: 5,
recipe: "RecipeMint123"
});
if (status === "error") {
console.error("Failed to start crafting:", error);
return;
}
console.log("Crafting started:", data);