Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ package-lock.json
i18n.cache
en/
.env
.claude/
.claude
.tool-versions
95 changes: 50 additions & 45 deletions audit.csv

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@
"pages": [
"index",
"quickstart",
{
"group": "Quickstart by persona",
"pages": [
"quickstart/trader",
"quickstart/wallet",
"quickstart/indexer",
"quickstart/defi",
"quickstart/nft"
]
},
"billing/plans",
"billing/credits",
"billing/rate-limits"
Expand Down
1 change: 1 addition & 0 deletions examples/quickstarts/defi/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HELIUS_API_KEY=
15 changes: 15 additions & 0 deletions examples/quickstarts/defi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# DeFi quickstart

Watches Pump.fun AMM swaps in real time. [Enhanced WebSockets `transactionSubscribe`](https://www.helius.dev/docs/websockets/transaction-subscribe) for the live stream, [Enhanced Transactions `parseTransactions`](https://www.helius.dev/docs/enhanced-transactions/parse-transactions) for typed swap events.

Requires a **Developer+ plan**.

## Run it

```bash
cp .env.example .env # add HELIUS_API_KEY
npm install
npm start
```

Full walkthrough: [DeFi quickstart](https://www.helius.dev/docs/quickstart/defi).
21 changes: 21 additions & 0 deletions examples/quickstarts/defi/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "helius-quickstart-defi",
"version": "1.0.0",
"private": true,
"description": "DeFi quickstart — watch Pump.fun AMM swaps via Enhanced WebSockets + Enhanced Transactions parsing.",
"type": "module",
"scripts": {
"start": "tsx src/index.ts"
},
"dependencies": {
"dotenv": "^16.4.0",
"helius-sdk": "^2.0.0",
"ws": "^8.18.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"@types/ws": "^8.5.10",
"tsx": "^4.19.0",
"typescript": "^5.5.0"
}
}
63 changes: 63 additions & 0 deletions examples/quickstarts/defi/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* DeFi quickstart — watch Pump.fun AMM swaps in real time. Combines:
* - Enhanced WebSockets transactionSubscribe (filtered live stream)
* - Enhanced Transactions parseTransactions (typed swap events)
*/

import "dotenv/config";
import WebSocket from "ws";
import { Helius } from "helius-sdk";

const apiKey = process.env.HELIUS_API_KEY;
if (!apiKey) {
console.error("Set HELIUS_API_KEY in .env (see .env.example).");
process.exit(1);
}

const helius = new Helius(apiKey);
const PUMP_AMM = "pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA";

const ws = new WebSocket(`wss://mainnet.helius-rpc.com/?api-key=${apiKey}`);

ws.on("open", () => {
console.log("connected — watching Pump AMM swaps");
ws.send(JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "transactionSubscribe",
params: [
{ vote: false, failed: false, accountInclude: [PUMP_AMM] },
{ commitment: "confirmed", encoding: "jsonParsed", transactionDetails: "full", maxSupportedTransactionVersion: 0 },
],
}));
setInterval(() => ws.ping(), 30_000);
});

ws.on("message", async (raw) => {
const msg = JSON.parse(raw.toString());
if (msg.method !== "transactionNotification") return;

const sig = msg.params.result.transaction.transaction.signatures[0];

try {
const [parsed] = await helius.rpc.parseTransactions({ transactions: [sig] });
if (parsed?.type !== "SWAP") return;

const swap = parsed.events?.swap;
if (!swap) return;
const tokenIn = swap.tokenInputs?.[0];
const tokenOut = swap.tokenOutputs?.[0];

console.log(
`[${parsed.timestamp}] ${parsed.feePayer.slice(0, 4)}…${parsed.feePayer.slice(-4)}`,
`swap ${tokenIn?.tokenAmount} ${tokenIn?.mint?.slice(0, 4)}…`,
`→ ${tokenOut?.tokenAmount} ${tokenOut?.mint?.slice(0, 4)}…`,
`(${sig.slice(0, 20)}…)`
);
} catch (err) {
console.error("parse error:", err);
}
});

ws.on("error", (err) => console.error("ws error:", err));
ws.on("close", (code) => console.log("closed:", code));
10 changes: 10 additions & 0 deletions examples/quickstarts/defi/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "Bundler",
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true
}
}
4 changes: 4 additions & 0 deletions examples/quickstarts/indexer/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
HELIUS_API_KEY=

# Optional — defaults to US East. See https://www.helius.dev/docs/laserstream#mainnet-endpoints
# LASERSTREAM_ENDPOINT=https://laserstream-mainnet-fra.helius-rpc.com
15 changes: 15 additions & 0 deletions examples/quickstarts/indexer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Indexer quickstart

Subscribes to Jupiter aggregator V6 transactions via [LaserStream gRPC](https://www.helius.dev/docs/laserstream) and prints each one. Marked-up persistence hook ready for your DB.

Requires a **Business+ plan on Mainnet** or **Developer+ plan on Devnet**.

## Run it

```bash
cp .env.example .env # add HELIUS_API_KEY
npm install
npm start
```

Full walkthrough: [Indexer quickstart](https://www.helius.dev/docs/quickstart/indexer).
19 changes: 19 additions & 0 deletions examples/quickstarts/indexer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "helius-quickstart-indexer",
"version": "1.0.0",
"private": true,
"description": "Indexer quickstart — subscribe to Jupiter transactions via LaserStream gRPC.",
"type": "module",
"scripts": {
"start": "tsx src/index.ts"
},
"dependencies": {
"dotenv": "^16.4.0",
"helius-laserstream": "^1.0.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"tsx": "^4.19.0",
"typescript": "^5.5.0"
}
}
72 changes: 72 additions & 0 deletions examples/quickstarts/indexer/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Indexer quickstart — subscribe to Jupiter aggregator V6 transactions via
* LaserStream gRPC. Prints each transaction; the persistence hook is marked
* with a comment so you can wire your DB of choice.
*/

import "dotenv/config";
import {
subscribe,
LaserstreamConfig,
CommitmentLevel,
SubscribeRequest,
} from "helius-laserstream";

const apiKey = process.env.HELIUS_API_KEY;
if (!apiKey) {
console.error("Set HELIUS_API_KEY in .env (see .env.example).");
process.exit(1);
}

const config: LaserstreamConfig = {
apiKey,
endpoint: process.env.LASERSTREAM_ENDPOINT ?? "https://laserstream-mainnet-ewr.helius-rpc.com",
};

const JUPITER = "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4";

const request: SubscribeRequest = {
transactions: {
jupiter: {
vote: false,
failed: false,
accountInclude: [JUPITER],
accountExclude: [],
accountRequired: [],
},
},
accounts: {},
slots: {},
blocks: {},
blocksMeta: {},
entry: {},
transactionsStatus: {},
accountsDataSlice: [],
commitment: CommitmentLevel.CONFIRMED,
};

let count = 0;
const start = Date.now();

await subscribe(
config,
request,
(data) => {
if (data.transaction) {
count++;
const sig = Buffer.from(data.transaction.transaction.signature).toString("base64");
const slot = data.transaction.slot;
console.log(`[${count}] slot=${slot} sig=${sig.slice(0, 20)}...`);

// Production indexer hook:
// await db.insert("transactions", { signature: sig, slot, raw: data });
}
if (data.pong) {
const elapsed = ((Date.now() - start) / 1000).toFixed(0);
console.log(`heartbeat — ${count} txs in ${elapsed}s`);
}
},
(err) => {
console.error("stream error:", err);
}
);
10 changes: 10 additions & 0 deletions examples/quickstarts/indexer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "Bundler",
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true
}
}
1 change: 1 addition & 0 deletions examples/quickstarts/nft/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HELIUS_API_KEY=
15 changes: 15 additions & 0 deletions examples/quickstarts/nft/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# NFT quickstart

Fetches a wallet's full NFT portfolio (standard + compressed), groups by collection, prints a summary. Uses [DAS `getAssetsByOwner`](https://www.helius.dev/docs/das/get-nfts).

## Run it

```bash
cp .env.example .env # add HELIUS_API_KEY
npm install
npm start
# or pass any wallet address:
npx tsx src/index.ts <wallet-address>
```

Full walkthrough: [NFT quickstart](https://www.helius.dev/docs/quickstart/nft).
19 changes: 19 additions & 0 deletions examples/quickstarts/nft/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "helius-quickstart-nft",
"version": "1.0.0",
"private": true,
"description": "NFT quickstart — fetch a wallet's NFT portfolio with metadata via DAS getAssetsByOwner.",
"type": "module",
"scripts": {
"start": "tsx src/index.ts"
},
"dependencies": {
"dotenv": "^16.4.0",
"helius-sdk": "^2.0.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"tsx": "^4.19.0",
"typescript": "^5.5.0"
}
}
51 changes: 51 additions & 0 deletions examples/quickstarts/nft/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* NFT quickstart — fetch a wallet's full NFT portfolio via DAS, group by
* collection, and print a summary. The query a marketplace makes for a
* portfolio screen.
*/

import "dotenv/config";
import { Helius } from "helius-sdk";

const apiKey = process.env.HELIUS_API_KEY;
if (!apiKey) {
console.error("Set HELIUS_API_KEY in .env (see .env.example).");
process.exit(1);
}

const helius = new Helius(apiKey);
const owner = process.argv[2] ?? "86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY";

const items: Array<any> = [];
for (let page = 1; ; page++) {
const res = await helius.rpc.getAssetsByOwner({
ownerAddress: owner,
page,
limit: 100,
displayOptions: { showFungible: false, showCollectionMetadata: true },
});
items.push(...res.items);
if (res.items.length < 100) break;
}

console.log(`\n=== NFT portfolio: ${owner} ===`);
console.log(`Total NFTs: ${items.length}\n`);

const byCollection = new Map<string, Array<any>>();
for (const a of items) {
const collection =
a.grouping?.find((g: any) => g.group_key === "collection")?.group_value ?? "Individual";
if (!byCollection.has(collection)) byCollection.set(collection, []);
byCollection.get(collection)!.push(a);
}

const sorted = [...byCollection.entries()].sort((a, b) => b[1].length - a[1].length);
for (const [collection, list] of sorted) {
const compressed = list.filter((a) => a.compression?.compressed).length;
console.log(`${collection.slice(0, 40)} — ${list.length} (${compressed} compressed)`);
for (const a of list.slice(0, 3)) {
const name = a.content?.metadata?.name ?? "Unnamed";
console.log(` · ${name}`);
}
if (list.length > 3) console.log(` · … +${list.length - 3} more`);
}
10 changes: 10 additions & 0 deletions examples/quickstarts/nft/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "Bundler",
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true
}
}
4 changes: 4 additions & 0 deletions examples/quickstarts/trader/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
HELIUS_API_KEY=
# Base58-encoded secret key for a dev wallet only. Anyone with this string
# can drain the wallet — never use a production key here.
WALLET_SECRET_KEY=
26 changes: 26 additions & 0 deletions examples/quickstarts/trader/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Trader quickstart

Sends a 0.0001 SOL self-transfer through [Helius Sender](https://www.helius.dev/docs/sending-transactions/sender) with a priority fee from the [Priority Fee API](https://www.helius.dev/docs/priority-fee-api).

The same code path a trading hot-path uses for time-sensitive sends.

## Run it

```bash
cp .env.example .env
# Fill in HELIUS_API_KEY and WALLET_SECRET_KEY (dev wallet, base58)

npm install
npm start
```

Expected output:

```
wallet: 7xK...
priority fee: 87000 microLamports per CU
submitted: 4xK...long-base58-signature...gJ
landed at slot 297148321 (842 ms)
```

Full walkthrough: [Trader quickstart](https://www.helius.dev/docs/quickstart/trader).
Loading
Loading