The SDK can deploy a program from local build artifacts in one call. There are
two flavors: auto-discovery for Anchor/Agave workspaces with conventional
paths, and explicit deployment when you want to control where the bytes come
from.
Both flavors register the program at the IDL’s declared address (or at the
keypair file’s public key) and, if an IDL is available, register it with the
runtime via surfnet_registerIdl so RPC clients can decode account data.
Auto-Discover An Anchor Workspace
deployProgram / deploy_program takes the program name and looks for these
files relative to the current working directory:
use surfpool_sdk::Surfnet;
let surfnet = Surfnet::start().await?;
let cheats = surfnet.cheatcodes();
let program_id = cheats.deploy_program("my_program")?;
println!("deployed at {program_id}");
import { Surfnet } from "@solana/surfpool";
const surfnet = Surfnet.start();
try {
const programId = surfnet.deployProgram("my_program");
console.log("deployed at", programId);
} finally {
surfnet.stop();
}
Build before you deployRun anchor build (or cargo build-sbf) before calling deployProgram so
the .so and keypair artifacts actually exist on disk. The SDK does not
invoke the build for you.
Explicit Deployment
When the artifacts live somewhere non-standard — a built CI artifact, a
pre-baked test fixture, an embedded byte slice — pass an explicit deploy
configuration.
use surfpool_sdk::cheatcodes::builders::DeployProgram;
use surfpool_sdk::Surfnet;
let surfnet = Surfnet::start().await?;
let cheats = surfnet.cheatcodes();
// Derive the program ID from a keypair file.
let program_id = cheats.deploy(
DeployProgram::from_keypair_path("fixtures/my_program-keypair.json")?
.so_path("fixtures/my_program.so")
.idl_path("fixtures/my_program.idl.json"),
)?;
const surfnet = Surfnet.start();
const programId = "DemoProgram111111111111111111111111111111111";
surfnet.deploy({
programId,
soPath: "fixtures/my_program.so",
idlPath: "fixtures/my_program.idl.json"
});
surfnet.stop();
Deploy From Raw Bytes
When the bytecode is already in memory — generated by a build step, downloaded
from an artifact store, or embedded via include_bytes! — skip the file system
entirely.
use surfpool_sdk::cheatcodes::builders::DeployProgram;
use surfpool_sdk::{Pubkey, Surfnet};
const PROGRAM_BYTES: &[u8] = include_bytes!("../fixtures/my_program.so");
let surfnet = Surfnet::start().await?;
let cheats = surfnet.cheatcodes();
let program_id: Pubkey = "DemoProgram111111111111111111111111111111111".parse()?;
cheats.deploy(
DeployProgram::new(program_id).so_bytes(PROGRAM_BYTES.to_vec()),
)?;
import { readFileSync } from "node:fs";
const surfnet = Surfnet.start();
const programBytes = readFileSync("fixtures/my_program.so");
surfnet.deploy({
programId: "DemoProgram111111111111111111111111111111111",
soBytes: programBytes
});
surfnet.stop();
DeployProgram Builder Reference (Rust)
DeployOptions Type Reference (JS)
type ByteArrayLike = Uint8Array | number[];
interface DeployOptions {
programId: string; // base58 address to deploy at
soPath?: string; // path to .so on disk
soBytes?: ByteArrayLike; // or raw bytes in memory
idlPath?: string; // optional Anchor IDL JSON
}
Provide one of soPath or soBytes. If neither is set, deploy throws
deploy requires either soPath or soBytes. If both are set, soPath takes
precedence.
What Gets Registered
After a successful deploy, the runtime does three things:
- Writes the program account at
programId with the .so bytes via
surfnet_writeProgram.
- Marks the account executable so it can be invoked through normal RPC
calls.
- Registers the IDL (if provided) via
surfnet_registerIdl, which lets RPC
clients decode account data using the program’s IDL schema.
Rare: non-executable program accountIf you want to write program bytes to an account but keep it non-executable,
use SetAccount directly instead of deploy. The deploy path always marks
the account executable.
Errors