Пакет @solana/surfpool надає один клас, Surfnet, а також допоміжні типи,
необхідні для типобезпечного виклику його методів. На цій сторінці перераховано
всі експортовані символи; для ознайомлення з принципами використання зверніться
до посібників, починаючи з Огляду.
Експорти пакета
| Символ | Вид | Примітки |
|---|---|---|
Surfnet | клас | Запущений екземпляр Surfnet з методами чіткодів |
SurfnetConfig | тип | Аргумент для Surfnet.startWithConfig |
DeployOptions | тип | Аргумент для Surfnet.deploy |
SetTokenAccountUpdate | тип | Аргумент для Surfnet.setTokenAccount |
ResetAccountOptions | тип | Аргумент для Surfnet.resetAccount |
StreamAccountOptions | тип | Аргумент для Surfnet.streamAccount |
SolAccountFunding | тип | Елемент масиву, що передається до Surfnet.fundSolMany |
SimnetEventValue | тип | Елемент, що повертається з Surfnet.drainEvents |
KeypairInfo | тип | Повертається з Surfnet.newKeypair |
ClockValue | тип | Поле в SimnetEventValue |
EpochInfoValue | тип | Повертається допоміжними функціями подорожі в часі |
ByteArrayLike | тип | Uint8Array | number[] — гнучкий байтовий ввід |
Клас Surfnet
Статичні методи
class Surfnet {static start(): Surfnet;static startWithConfig(config: SurfnetConfig): Surfnet;static newKeypair(): KeypairInfo;}
Властивості екземпляра
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;}
Життєвий цикл
class Surfnet {stop(): void; // idempotent; safe to call from `finally` / test teardown}
Чіткоди 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;}
Чіткоди токенів
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;}
Подорож у часі
class Surfnet {timeTravelToSlot(slot: number): EpochInfoValue;timeTravelToEpoch(epoch: number): EpochInfoValue;timeTravelToTimestamp(timestampMs: number): EpochInfoValue;}
Розгортання програм
class Surfnet {deployProgram(programName: string): string; // returns program iddeploy(options: DeployOptions): string; // returns program id}
Потокова передача та події
class Surfnet {streamAccount(address: string, options?: StreamAccountOptions): void;drainEvents(): SimnetEventValue[];}
Типи конфігурації
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[];
Там, де метод приймає ByteArrayLike, можна передати або Uint8Array, або
звичайний числовий масив. Обгортка нормалізує обидва варіанти у формат, який
очікує нативне прив'язування.
Типи подій
SimnetEventValue
Плаский об'єкт із дискримінатором kind та необов'язковими полями. Дивіться
Події для каталогу варіантів.
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;}
Помилки
Кожен метод викидає стандартний Error, повідомлення якого обгортає базову
Rust-помилку SurfnetError. Перевіряйте error.message для розрізнення між
випадками.
try {surfnet.deploy({ programId, soPath: "missing.so" });} catch (err) {// err.message starts with "Cheatcode:" / "Startup:" / etc.console.error(err);}
Розмір нативного модуля
Пакет залежить від платформо-специфічних нативних бінарних файлів, опублікованих
як optionalDependencies:
| Triple | Package |
|---|---|
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 |
Якщо жоден із платформних пакетів не встановлюється на вашій машині,
Surfnet.start() видає помилку під час першого виклику з чітким повідомленням
«нативний модуль не знайдено». Дивіться
Встановлення для ознайомлення з
матрицею підтримки та усуненням несправностей.
Is this page helpful?