مرجع JS API

تعرض حزمة @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 key
readonly payerSecretKey: Uint8Array; // 64-byte private key
readonly 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 id
deploy(options: DeployOptions): string; // returns program id
}

البث والأحداث

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

أنواع الإعدادات

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

حيثما تقبل الدالة 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:

الثلاثيالحزمة
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?