Gói @solana/surfpool cung cấp một lớp, Surfnet, cùng với các kiểu hỗ trợ bạn
cần để gọi các phương thức của nó một cách an toàn về kiểu. Trang này liệt kê
mọi ký hiệu được xuất; để xem hướng dẫn sử dụng theo ngữ cảnh, hãy xem các tài
liệu bắt đầu bằng Tổng quan.
Các Export của Gói
| Ký hiệu | Loại | Ghi chú |
|---|---|---|
Surfnet | class | Phiên bản Surfnet đang chạy với các phương thức cheatcode |
SurfnetConfig | type | Đối số cho Surfnet.startWithConfig |
DeployOptions | type | Đối số cho Surfnet.deploy |
SetTokenAccountUpdate | type | Đối số cho Surfnet.setTokenAccount |
ResetAccountOptions | type | Đối số cho Surfnet.resetAccount |
StreamAccountOptions | type | Đối số cho Surfnet.streamAccount |
SolAccountFunding | type | Phần tử của mảng truyền vào Surfnet.fundSolMany |
SimnetEventValue | type | Phần tử được trả về bởi Surfnet.drainEvents |
KeypairInfo | type | Được trả về bởi Surfnet.newKeypair |
ClockValue | type | Trường trên SimnetEventValue |
EpochInfoValue | type | Được trả về bởi các hàm trợ giúp du hành thời gian |
ByteArrayLike | type | Uint8Array | number[] — đầu vào byte linh hoạt |
Lớp Surfnet
Phương thức Tĩnh
class Surfnet {static start(): Surfnet;static startWithConfig(config: SurfnetConfig): Surfnet;static newKeypair(): KeypairInfo;}
Thuộc tính Phiên bản
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;}
Vòng đời
class Surfnet {stop(): void; // idempotent; safe to call from `finally` / test teardown}
Cheatcode 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;}
Cheatcode Token
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;}
Du hành Thời gian
class Surfnet {timeTravelToSlot(slot: number): EpochInfoValue;timeTravelToEpoch(epoch: number): EpochInfoValue;timeTravelToTimestamp(timestampMs: number): EpochInfoValue;}
Triển khai Chương trình
class Surfnet {deployProgram(programName: string): string; // returns program iddeploy(options: DeployOptions): string; // returns program id}
Luồng & Sự kiện
class Surfnet {streamAccount(address: string, options?: StreamAccountOptions): void;drainEvents(): SimnetEventValue[];}
Các Kiểu Cấu hình
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[];
Khi một phương thức chấp nhận ByteArrayLike, bạn có thể truyền vào
Uint8Array hoặc một mảng số thông thường. Lớp bao bọc sẽ chuẩn hóa cả hai về
định dạng mà liên kết native mong đợi.
Các Loại Sự Kiện
SimnetEventValue
Một đối tượng phẳng với bộ phân biệt kind và các trường tùy chọn. Xem
Sự kiện để biết danh mục biến thể.
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;}
Lỗi
Mỗi phương thức đều ném ra một Error tiêu chuẩn có thông báo bao bọc lỗi Rust
SurfnetError bên dưới. Kiểm tra error.message để phân biệt giữa các trường
hợp.
try {surfnet.deploy({ programId, soPath: "missing.so" });} catch (err) {// err.message starts with "Cheatcode:" / "Startup:" / etc.console.error(err);}
Dung Lượng Module Gốc
Gói phụ thuộc vào các tệp nhị phân gốc dành riêng cho từng nền tảng, được xuất
bản dưới dạng 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 |
Nếu không có gói nền tảng nào được cài đặt trên máy của bạn, Surfnet.start()
sẽ báo lỗi ngay lần gọi đầu tiên với thông báo rõ ràng "không tìm thấy module
gốc". Xem Cài đặt để biết ma trận hỗ
trợ và cách khắc phục sự cố.
Is this page helpful?