JS API-referentie

Het pakket @solana/surfpool bevat één klasse, Surfnet, samen met de ondersteunende types die je nodig hebt om de methoden type-veilig aan te roepen. Op deze pagina staan alle geëxporteerde symbolen; voor inhoudelijk gebruik, zie de handleidingen te beginnen met Overzicht.

Pakketexports

SymboolSoortOpmerkingen
SurfnetklasseActieve Surfnet-instantie met cheatcode-methoden
SurfnetConfigtypeArgument voor Surfnet.startWithConfig
DeployOptionstypeArgument voor Surfnet.deploy
SetTokenAccountUpdatetypeArgument voor Surfnet.setTokenAccount
ResetAccountOptionstypeArgument voor Surfnet.resetAccount
StreamAccountOptionstypeArgument voor Surfnet.streamAccount
SolAccountFundingtypeElement van de array doorgegeven aan Surfnet.fundSolMany
SimnetEventValuetypeElement geretourneerd door Surfnet.drainEvents
KeypairInfotypeGeretourneerd door Surfnet.newKeypair
ClockValuetypeVeld op SimnetEventValue
EpochInfoValuetypeGeretourneerd door tijdreishelpers
ByteArrayLiketypeUint8Array | number[] — flexibele byte-invoer

Surfnet-klasse

Statische methoden

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

Instantie-eigenschappen

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;
}

Levenscyclus

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;
}

Tijdreizen

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

Programma-implementatie

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

Streaming & Gebeurtenissen

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

Configuratietypes

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[];

Waar een methode ByteArrayLike accepteert, kunt u ofwel een Uint8Array of een gewone getallenarray doorgeven. De wrapper normaliseert beide naar het formaat dat de native binding verwacht.

Gebeurtenistypen

SimnetEventValue

Een plat object met een kind-discriminator en optionele velden. Zie Gebeurtenissen voor de variantencatalogus.

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;
}

Fouten

Elke methode gooit een standaard Error waarvan het bericht de onderliggende Rust SurfnetError omhult. Inspecteer error.message om onderscheid te maken tussen gevallen.

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

Native Module Footprint

Het pakket is afhankelijk van platformspecifieke native binaries die zijn gepubliceerd als optionalDependencies:

TriplePackage
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

Als geen van de platformpakketten op uw machine wordt geïnstalleerd, genereert Surfnet.start() bij de eerste aanroep een duidelijke foutmelding "native module niet gevonden". Zie Installatie voor de ondersteuningsmatrix en probleemoplossing.

Is this page helpful?

© 2026 Solana Foundation. Alle rechten voorbehouden.