Skip to main content
Version: 0.12

Note Transport with the Miden SDK

This guide demonstrates how to use the note transport features in the Miden SDK. Note transport allows you to send and receive private notes using the Miden Note Transport network.

Initializing the Client with Note Transport

To use note transport features, you need to initialize the client with a note transport endpoint URL:

import { WebClient } from "@demox-labs/miden-sdk";

try {
// Initialize the web client with note transport endpoint
const webClient = await WebClient.createClient(
null, // Miden node endpoint (optional, defaults to testnet)
"http://localhost:57292", // Miden Note Transport node
null // seed (optional)
);

console.log("Client initialized with note transport");
} catch (error) {
console.error("Failed to initialize client:", error.message);
}

Sending Private Notes

To send a private note, use sendPrivateNote():

import { WebClient, Note, Address } from "@demox-labs/miden-sdk";

try {
// Initialize the web client with note transport endpoint
const webClient = await WebClient.createClient(null, "http://localhost:57292", null);

const note = /* note to be sent here */;
const address = /* recipient's address here */;

// Send the private note
await webClient.sendPrivateNote(note, address);

console.log("Private note sent successfully");
} catch (error) {
console.error("Failed to send private note:", error.message);
}

Fetching Private Notes

To fetch private notes from the note transport layer, use fetchPrivateNotes().

import { WebClient, NoteFilter, NoteFilterTypes } from "@demox-labs/miden-sdk";

try {
// Initialize the web client with note transport endpoint
const webClient = await WebClient.createClient(null, "http://localhost:57292", null);

// Fetch private notes using pagination
await webClient.fetchPrivateNotes();

// Alternatively, fetch all private notes without pagination.
// Reserve this for special cases like initial setup or troubleshooting.
// await webClient.fetchAllPrivateNotes();

// Retrieve the fetched notes
const filter = new NoteFilter(NoteFilterTypes.All);
const notes = await webClient.getInputNotes(filter);

console.log(`Fetched ${notes.length} private notes`);
} catch (error) {
console.error("Failed to fetch private notes:", error.message);
}

Relevant Documentation

For more detailed information about note transport functionality, refer to the following API documentation:

  • WebClient - Main client class for note transport operations
  • Note - Class for working with notes
  • Address - Class for working with addresses
  • NoteFilter - Class for filtering notes
  • NoteFilterTypes - Enumeration for note filter types

For a complete list of available classes and utilities, see the SDK API Reference.