JS API Referenz

Das Paket @solana/surfpool stellt eine Klasse bereit, Surfnet, sowie die unterstützenden Typen, die Sie benötigen, um dessen Methoden typsicher aufzurufen. Diese Seite listet alle exportierten Symbole auf; für eine erklärende Einführung siehe die Anleitungen beginnend mit Übersicht.

Paketexporte

SymbolArtHinweise
SurfnetKlasseLaufende Surfnet-Instanz mit Cheatcode-Methoden
SurfnetConfigTypArgument für Surfnet.startWithConfig
DeployOptionsTypArgument für Surfnet.deploy
SetTokenAccountUpdateTypArgument für Surfnet.setTokenAccount
ResetAccountOptionsTypArgument für Surfnet.resetAccount
StreamAccountOptionsTypArgument für Surfnet.streamAccount
SolAccountFundingTypElement des Arrays, das an Surfnet.fundSolMany übergeben wird
SimnetEventValueTypVon Surfnet.drainEvents zurückgegebenes Element
KeypairInfoTypZurückgegeben von Surfnet.newKeypair
ClockValueTypFeld in SimnetEventValue
EpochInfoValueTypZurückgegeben von Zeitreise-Hilfsfunktionen
ByteArrayLikeTypUint8Array | number[] — flexible Byte-Eingabe

Surfnet-Klasse

Statische Methoden

class Surfnet {
static start(): Surfnet;
static startWithConfig(config: SurfnetConfig): Surfnet;
static newKeypair(): KeypairInfo;
}

Instanzeigenschaften

class Surfnet {
readonly rpcUrl: string; // http://127.0.0.1:<port>
readonly wsUrl: string; // ws://127.0.0.1:<port>
readonly payer: string; // base58 public key
readonly payerSecretKey: Uint8Array; // 64-byte private key
readonly instanceId: string;
}

Lebenszyklus

class Surfnet {
stop(): void; // idempotent; safe to call from `finally` / test teardown
}

SOL-Cheatcodes

class Surfnet {
fundSol(address: string, lamports: number): void;
fundSolMany(accounts: SolAccountFunding[]): void;
setAccount(
address: string,
lamports: number,
data: Uint8Array,
owner: string
): void;
resetAccount(address: string, options?: ResetAccountOptions): void;
}

Token-Cheatcodes

class Surfnet {
fundToken(
owner: string,
mint: string,
amount: number,
tokenProgram?: string
): void;
fundTokenMany(
owners: string[],
mint: string,
amount: number,
tokenProgram?: string
): void;
setTokenBalance(
owner: string,
mint: string,
amount: number,
tokenProgram?: string
): void;
setTokenAccount(
owner: string,
mint: string,
update: SetTokenAccountUpdate,
tokenProgram?: string
): void;
getAta(owner: string, mint: string, tokenProgram?: string): string;
}

Zeitreise

class Surfnet {
timeTravelToSlot(slot: number): EpochInfoValue;
timeTravelToEpoch(epoch: number): EpochInfoValue;
timeTravelToTimestamp(timestampMs: number): EpochInfoValue;
}

Programm-Deployment

class Surfnet {
deployProgram(programName: string): string; // returns program id
deploy(options: DeployOptions): string; // returns program id
}

Streaming & Events

class Surfnet {
streamAccount(address: string, options?: StreamAccountOptions): void;
drainEvents(): SimnetEventValue[];
}

Konfigurationstypen

SurfnetConfig

interface SurfnetConfig {
offline?: boolean; // default: true
remoteRpcUrl?: string; // setting this implies offline=false
blockProductionMode?: "manual" | "clock" | "transaction"; // default: "transaction"
slotTimeMs?: number; // default: 1
airdropSol?: number; // lamports; default: 10_000_000_000
airdropAddresses?: string[];
payerSecretKey?: ByteArrayLike;
enableFeatures?: string[]; // feature IDs (base58 or kebab name)
disableFeatures?: string[];
allFeatures?: boolean;
}

DeployOptions

interface DeployOptions {
programId: string; // base58 address
soPath?: string; // mutually exclusive with soBytes
soBytes?: ByteArrayLike;
idlPath?: string; // optional Anchor IDL JSON
}

SetTokenAccountUpdate

interface SetTokenAccountUpdate {
amount?: number;
delegate?: string; // base58 pubkey
clearDelegate?: boolean;
state?: string; // e.g. "initialized", "frozen"
delegatedAmount?: number;
closeAuthority?: string;
clearCloseAuthority?: boolean;
}

ResetAccountOptions

interface ResetAccountOptions {
includeOwnedAccounts?: boolean;
}

StreamAccountOptions

interface StreamAccountOptions {
includeOwnedAccounts?: boolean;
}

SolAccountFunding

interface SolAccountFunding {
address: string;
lamports: number;
}

KeypairInfo

interface KeypairInfo {
publicKey: string; // base58
secretKey: number[]; // 64 bytes
}

ByteArrayLike

type ByteArrayLike = Uint8Array | number[];

Wo eine Methode ByteArrayLike akzeptiert, können Sie entweder ein Uint8Array oder ein einfaches Zahlen-Array übergeben. Der Wrapper normalisiert beide in das Format, das die native Binding erwartet.

Ereignistypen

SimnetEventValue

Ein flaches Objekt mit einem kind-Diskriminator und optionalen Feldern. Siehe Ereignisse für den Variantenkatalog.

interface SimnetEventValue {
kind: string;
message?: string;
timestamp?: string;
initialTransactionCount?: number;
clock?: ClockValue;
epochInfo?: EpochInfoValue;
accountPubkey?: string;
clockCommand?: string;
slotIntervalMs?: number;
transactionSignature?: string;
logs?: string[];
computeUnitsConsumed?: number;
fee?: number;
errorMessage?: string;
tag?: string;
profileKey?: string;
profileSlot?: number;
runbookId?: string;
runbookErrors?: string[];
}

ClockValue

interface ClockValue {
slot: number;
epoch: number;
leaderScheduleEpoch: number;
unixTimestamp: number;
epochStartTimestamp: number;
}

EpochInfoValue

interface EpochInfoValue {
absoluteSlot: number;
slotIndex: number;
slotsInEpoch: number;
epoch: number;
blockHeight: number;
transactionCount?: number;
}

Fehler

Jede Methode wirft einen standardmäßigen Error, dessen Nachricht den zugrunde liegenden Rust- SurfnetError umschließt. Untersuchen Sie error.message, um zwischen den Fällen zu unterscheiden.

try {
surfnet.deploy({ programId, soPath: "missing.so" });
} catch (err) {
// err.message starts with "Cheatcode:" / "Startup:" / etc.
console.error(err);
}

Footprint des nativen Moduls

Das Paket hängt von plattformspezifischen nativen Binärdateien ab, die als optionalDependencies veröffentlicht werden:

TriplePaket
aarch64-apple-darwin@solana/surfpool-darwin-arm64
x86_64-apple-darwin@solana/surfpool-darwin-x64
x86_64-unknown-linux-gnu@solana/surfpool-linux-x64-gnu

Wenn keines der Plattformpakete auf Ihrem System installiert werden kann, wirft Surfnet.start() beim ersten Aufruf einen eindeutigen Fehler „Natives Modul nicht gefunden“. Die Support-Matrix und Fehlerbehebung finden Sie unter Installation.

Is this page helpful?

© 2026 Solana Foundation. Alle Rechte vorbehalten.