Prerequisites
- Node.js 22+ installed
- TypeScript project initialized
Complete Code
View complete code with explanations
View complete code with explanations
The complete code retrieves and decodes Orca Whirlpool swap instructions from Solana mainnet.
index.ts
How it works
- Portal source:
solanaPortalSourceconnects to the Portal API and streams Solana blockchain data - Decoder:
solanaInstructionDecoderfilters and decodes program instructions using ABIs - Pipe:
.pipe()chains the decoder to the source - Stream: The
for awaitloop processes batches of decoded data as they arrive
Data structure
Each decoded swap instruction contains:blockNumber: Slot number where the instruction occurredtimestamp: Block timestampprogramId: Program address that executed the instructiontransaction: Transaction details including signaturesinstruction: Decoded instruction fields (accounts, data)rawInstruction: Raw instruction data
Next steps
- Use
range: { from: 'latest' }to stream from the latest slots - Add multiple programs or instruction types
- Use
createTargetto persist data to a database - See Basics for more examples

