Package Exports
- @solsdk/relay_sdk
Readme
@solsdk/relay_sdk
TypeScript SDK for seamless token trading and relay integration
Create · Buy · Sell · Relay · Jito Bundles
Modern, robust, and production-ready SDK for token trading and relay operations on Solana.
✅ Reliable buy/sell/create flows
✅ Support for the latest event formats
✅ Jito and multiple relay integrations (Astra, 0Slot, NodeOne, NextBlock)
✅ Works on devnet and mainnet-beta
✅ ESM & CJS builds for maximum compatibility
✨ Features
| Module | Highlights |
|---|---|
SDK |
Unified entry point. Wraps Anchor Program & Connection and initializes all submodules. |
TradeModule |
createAndBuy, buy, sell, transaction builders, slippage helpers |
TokenModule |
Token metadata, ATA creation, mint helpers |
PdaModule |
PDA helpers: global, event-authority, bonding-curve, metadata, and more |
EventModule |
Typed Anchor event listeners with automatic deserialization |
JitoModule |
Submit Jito bundles for buy/sell. Requires jitoUrl and authKeypair in SDK options |
AstraModule |
Sends buy/sell transactions via Astra relays. Includes tip transfers and optional keep-alive |
SlotModule |
Optimized for 0Slot relays with buy() and ping() |
NextBlockModule |
Optimized for NextBlock relays with buy() and ping() |
NodeOneModule |
Optimized for NodeOne relays with buy() and ping() |
| IDL exports | Full IDL JSON and type helpers |
Note: Use
ping()on relay modules (e.g.,sdk.slot.ping()) periodically to keep upstream relay connections alive.
📦 Installation
npm install @solsdk/relay_sdk🔨 Quick Start
Replace DEVNET_RPC with your preferred Solana RPC endpoint.
const DEVNET_RPC = "https://api.devnet.solana.com";
const SLIPPAGE_BPS = 100n;
const PRIORITY_FEE = { unitLimit: 250_000, unitPrice: 250_000 };
const secret = JSON.parse(process.env.WALLET!);
const wallet = Keypair.fromSecretKey(Uint8Array.from(secret));
async function printSOL(conn: Connection, pk: PublicKey, label = "") {
const sol = (await conn.getBalance(pk)) / LAMPORTS_PER_SOL;
console.log(`${label} SOL:`, sol.toFixed(4));
}
async function main() {
const connection = new Connection(DEVNET_RPC, "confirmed");
const provider = new AnchorProvider(connection, new Wallet(wallet), {
commitment: "confirmed",
});
const sdk = new SDK(provider);
const mint = Keypair.generate();
await printSOL(connection, wallet.publicKey, "user");
const img = await import("node:fs/promises").then((fs) =>
fs.readFile("example/images/test.png")
);
const blob = new Blob([img], { type: "image/png" });
await sdk.trade.createAndBuy(
wallet,
mint,
{ name: "DEV-TEST", symbol: "DVT", description: "Devnet demo", file: blob },
0.0001 * LAMPORTS_PER_SOL,
SLIPPAGE_BPS,
PRIORITY_FEE
);
console.log(
"Token link →",
`https://pump.fun/${mint.publicKey}?cluster=devnet`
);
await sdk.trade.buy(
wallet,
mint.publicKey,
0.0002 * LAMPORTS_PER_SOL,
SLIPPAGE_BPS,
PRIORITY_FEE
);
const bal = await getSPLBalance(connection, mint.publicKey, wallet.publicKey);
console.log("Token balance:", bal / 10 ** DEFAULT_DECIMALS);
await sdk.trade.sell(
wallet,
mint.publicKey,
BigInt(bal),
SLIPPAGE_BPS,
PRIORITY_FEE
);
await printSOL(connection, wallet.publicKey, "user after sell");
}
main().catch(console.error);🚀 Advanced Usage
🧠 Buy with Jito
const sdk = new SDK(provider, {
jitoUrl: "ny.mainnet.block-engine.jito.wtf",
authKeypair: wallet,
});
await sdk.jito!.buyJito(
wallet,
mint.publicKey,
BigInt(0.0002 * LAMPORTS_PER_SOL),
SLIPPAGE_BPS,
500_000,
PRIORITY,
"confirmed"
);🛰️ Buy with 0Slot, NodeOne, Astra, or NextBlock
These modules use upstream relayers for ultra-fast transaction submission.
They support periodicping()to keep HTTPS connections alive and reduce TLS overhead.
const sdk = new SDK(provider, {
providerRegion: Region.Frankfurt,
slotKey: "your-api-key", // or astraKey / nextBlockKey / nodeOneKey
});
await sdk.slot!.ping();
await sdk.slot!.buy(
wallet,
mint.publicKey,
BigInt(0.0002 * LAMPORTS_PER_SOL),
SLIPPAGE_BPS,
500_000,
PRIORITY,
"confirmed"
);
AstraModule,NodeOneModule, andNextBlockModulefollow the same interface:buy(),sell(),ping()
Transactions are signed locally and relayed via HTTPS POST (base64-encoded) for speed.
🧩 What Does ping() Do?
Relay modules like SlotModule, AstraModule, NodeOneModule, and NextBlockModule implement ping().
Calling ping() periodically:
- Prevents connection idle timeouts
- Keeps the relay ready for low-latency submission
await sdk.astra!.ping();
await sdk.slot!.ping();🌐 Supported Relay Regions
Each relay provider supports a set of regions for optimal latency. Below are the currently supported regions per provider:
Slot 📍 Frankfurt • New York • Tokyo • Amsterdam • Los Angeles
Astra 📍 Frankfurt • New York • Tokyo • Amsterdam
NodeOne 📍 New York • Tokyo • Amsterdam • Frankfurt
NextBlock 📍 Tokyo • Frankfurt • New YorkSpecify
providerRegionin SDK options to select the regional relay.
🛡️ Why Choose @solsdk/relay_sdk?
- Actively maintained: Regular updates and fast issue resolution
- Strict TypeScript types: No
any, no type assertions, maximum safety - Best practices: KISS, DRY, SOLID, and more
- Production ready: Used in real-world trading bots and dApps
- Comprehensive tests: Ensuring reliability and stability
- Open source: MIT license, transparent development
⚠️ Disclaimer
This software is provided “as is,” without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement.
In no event shall the authors or copyright holders be liable for any claim, damages, or other liability—whether in an action of contract, tort, or otherwise—arising from, out of, or in connection with the software or the use or other dealings in the software.
Use at your own risk.
The authors take no responsibility for any harm or damage caused by the use of this software.
Users are responsible for ensuring the suitability and safety of this software for their specific use cases.
By using this software, you acknowledge that you have read, understood, and agree to this disclaimer.