Referência da API JS

O pacote @solana/surfpool expõe uma classe, Surfnet, além dos tipos de suporte necessários para chamar seus métodos com segurança de tipos. Esta página lista todos os símbolos exportados; para uso narrativo, consulte os guias a partir de Visão Geral.

Exportações do Pacote

SímboloTipoNotas
SurfnetclasseInstância em execução do Surfnet com métodos cheatcode
SurfnetConfigtipoArgumento para Surfnet.startWithConfig
DeployOptionstipoArgumento para Surfnet.deploy
SetTokenAccountUpdatetipoArgumento para Surfnet.setTokenAccount
ResetAccountOptionstipoArgumento para Surfnet.resetAccount
StreamAccountOptionstipoArgumento para Surfnet.streamAccount
SolAccountFundingtipoElemento do array passado para Surfnet.fundSolMany
SimnetEventValuetipoElemento retornado por Surfnet.drainEvents
KeypairInfotipoRetornado por Surfnet.newKeypair
ClockValuetipoCampo em SimnetEventValue
EpochInfoValuetipoRetornado pelos auxiliares de viagem no tempo
ByteArrayLiketipoUint8Array | number[] — entrada de bytes flexível

Classe Surfnet

Métodos Estáticos

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

Propriedades da Instância

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

Ciclo de Vida

class Surfnet {
stop(): void; // idempotent; safe to call from `finally` / test teardown
}

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

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

Viagem no Tempo

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

Deploy de Programa

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

Streaming e Eventos

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

Tipos de Configuração

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

Quando um método aceita ByteArrayLike, você pode passar um Uint8Array ou um array de números simples. O wrapper normaliza ambos no formato que o binding nativo espera.

Tipos de Eventos

SimnetEventValue

Um objeto simples com um discriminador kind e campos opcionais. Consulte Eventos para o catálogo de variantes.

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

Erros

Todo método lança um Error padrão cuja mensagem encapsula o SurfnetError Rust subjacente. Inspecione error.message para discriminar entre os casos.

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

Pegada do Módulo Nativo

O pacote depende de binários nativos específicos de plataforma publicados como optionalDependencies:

TriplePacote
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

Se nenhum dos pacotes de plataforma for instalado em sua máquina, Surfnet.start() lança um erro claro de "módulo nativo não encontrado" na primeira chamada. Consulte Instalação para a matriz de suporte e solução de problemas.

Is this page helpful?

© 2026 Fundação Solana. Todos os direitos reservados.