Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Getting Started

Installation

pnpm
pnpm add @0xslots/sdk @0xslots/contracts

Create a Client

import { SlotsClient, SlotsChain } from "@0xslots/sdk";
import { createPublicClient, createWalletClient, http } from "viem";
import { base } from "viem/chains";
 
const publicClient = createPublicClient({ chain: base, transport: http() });
 
// Read-only
const client = new SlotsClient({ chainId: SlotsChain.BASE, publicClient });
 
// Read + write
const walletClient = createWalletClient({
  account: privateKeyToAccount("0x..."),
  chain: base,
  transport: http(),
});
const client = new SlotsClient({ chainId: SlotsChain.BASE, publicClient, walletClient });

Read Slots

const { slots } = await client.getSlots({ first: 10 });
const { slot } = await client.getSlot({ id: "0x..." });
const info = await client.getSlotInfo("0x..."); // direct RPC read

Write Actions

import { parseEther } from "viem";
 
// Buy a slot (ERC-20 approval handled automatically)
await client.buy({
  slot: "0x...",
  depositAmount: parseEther("1"),
  selfAssessedPrice: parseEther("10"),
});
 
await client.selfAssess("0xSlot", parseEther("20"));
await client.topUp("0xSlot", parseEther("0.5"));
await client.withdraw("0xSlot", parseEther("0.1"));
await client.release("0xSlot");
await client.collect("0xSlot");       // permissionless
await client.liquidate("0xSlot");     // permissionless, earns bounty

React Integration

import { useSlotsClient, useSlotAction, useSlotOnChain } from "@0xslots/sdk/react";
 
function SlotView({ address }: { address: string }) {
  const { data: slot, isLoading } = useSlotOnChain(address, 8453);
  const { buy, busy } = useSlotAction({
    onSuccess: (label, hash) => console.log(`${label}: ${hash}`),
  });
 
  if (isLoading) return <div>Loading...</div>;
  if (!slot) return <div>Not found</div>;
 
  return (
    <div>
      <p>Price: {slot.price.toString()}</p>
      <p>Occupant: {slot.occupant ?? "Vacant"}</p>
      <button disabled={busy} onClick={() => buy({
        slot: address as `0x${string}`,
        depositAmount: 1000000n,
        selfAssessedPrice: 5000000n,
      })}>Buy</button>
    </div>
  );
}