Pakiet @solana/surfpool udostępnia jedną klasę, Surfnet, wraz z typami
pomocniczymi potrzebnymi do bezpiecznego typowo wywoływania jej metod. Na tej
stronie wymieniono wszystkie exportowane symbole; opis użycia narracyjnego
znajdziesz w przewodnikach, zaczynając od
Przeglądu.
Eksporty pakietu
| Symbol | Rodzaj | Uwagi |
|---|---|---|
Surfnet | klasa | Działająca instancja Surfnet z metodami cheatcode |
SurfnetConfig | typ | Argument do Surfnet.startWithConfig |
DeployOptions | typ | Argument do Surfnet.deploy |
SetTokenAccountUpdate | typ | Argument do Surfnet.setTokenAccount |
ResetAccountOptions | typ | Argument do Surfnet.resetAccount |
StreamAccountOptions | typ | Argument do Surfnet.streamAccount |
SolAccountFunding | typ | Element tablicy przekazywanej do Surfnet.fundSolMany |
SimnetEventValue | typ | Element zwracany przez Surfnet.drainEvents |
KeypairInfo | typ | Zwracany przez Surfnet.newKeypair |
ClockValue | typ | Pole w SimnetEventValue |
EpochInfoValue | typ | Zwracany przez pomocniki podróży w czasie |
ByteArrayLike | typ | Uint8Array | number[] — elastyczne wejście bajtowe |
Klasa Surfnet
Metody statyczne
class Surfnet {static start(): Surfnet;static startWithConfig(config: SurfnetConfig): Surfnet;static newKeypair(): KeypairInfo;}
Właściwości instancji
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 keyreadonly payerSecretKey: Uint8Array; // 64-byte private keyreadonly instanceId: string;}
Cykl życia
class Surfnet {stop(): void; // idempotent; safe to call from `finally` / test teardown}
Cheatcody SOL
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;}
Cheatcody tokenów
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;}
Podróż w czasie
class Surfnet {timeTravelToSlot(slot: number): EpochInfoValue;timeTravelToEpoch(epoch: number): EpochInfoValue;timeTravelToTimestamp(timestampMs: number): EpochInfoValue;}
Wdrożenie programu
class Surfnet {deployProgram(programName: string): string; // returns program iddeploy(options: DeployOptions): string; // returns program id}
Strumieniowanie i zdarzenia
class Surfnet {streamAccount(address: string, options?: StreamAccountOptions): void;drainEvents(): SimnetEventValue[];}
Typy konfiguracji
SurfnetConfig
interface SurfnetConfig {offline?: boolean; // default: trueremoteRpcUrl?: string; // setting this implies offline=falseblockProductionMode?: "manual" | "clock" | "transaction"; // default: "transaction"slotTimeMs?: number; // default: 1airdropSol?: number; // lamports; default: 10_000_000_000airdropAddresses?: string[];payerSecretKey?: ByteArrayLike;enableFeatures?: string[]; // feature IDs (base58 or kebab name)disableFeatures?: string[];allFeatures?: boolean;}
DeployOptions
interface DeployOptions {programId: string; // base58 addresssoPath?: string; // mutually exclusive with soBytessoBytes?: ByteArrayLike;idlPath?: string; // optional Anchor IDL JSON}
SetTokenAccountUpdate
interface SetTokenAccountUpdate {amount?: number;delegate?: string; // base58 pubkeyclearDelegate?: 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; // base58secretKey: number[]; // 64 bytes}
ByteArrayLike
type ByteArrayLike = Uint8Array | number[];
Jeśli metoda przyjmuje ByteArrayLike, można przekazać zarówno Uint8Array,
jak i zwykłą tablicę liczb. Wrapper normalizuje oba formaty do postaci
oczekiwanej przez natywne bindowanie.
Typy zdarzeń
SimnetEventValue
Płaski obiekt z dyskryminatorem kind i opcjonalnymi polami. Zobacz
Zdarzenia, aby zapoznać się z katalogiem
wariantów.
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;}
Błędy
Każda metoda zgłasza standardowy Error, którego wiadomość opakowuje bazowy
błąd Rust SurfnetError. Sprawdź error.message, aby rozróżnić poszczególne
przypadki.
try {surfnet.deploy({ programId, soPath: "missing.so" });} catch (err) {// err.message starts with "Cheatcode:" / "Startup:" / etc.console.error(err);}
Rozmiar modułu natywnego
Pakiet zależy od natywnych plików binarnych specyficznych dla platformy,
publikowanych jako optionalDependencies:
| Triple | Pakiet |
|---|---|
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 |
Jeśli żaden z pakietów platformy nie zainstaluje się na Twoim komputerze,
Surfnet.start() zgłasza błąd przy pierwszym wywołaniu z czytelnym komunikatem
„nie znaleziono modułu natywnego“. Zobacz
Instalację, aby zapoznać się z macierzą
obsługi i rozwiązywaniem problemów.
Is this page helpful?