- Node.js 18 or later
npm install @trufnetwork/sdk-js
# or
pnpm install @trufnetwork/sdk-js
# or
yarn add @trufnetwork/sdk-js
import { NodeTNClient, StreamId } from "@trufnetwork/sdk-js";
import { Wallet } from "ethers";
// Initialize client
const wallet = new Wallet(privateKey);
const chainId = await NodeTNClient.getDefaultChainId("https://staging.tsn.truflation.com");
const client = new NodeTNClient({
endpoint: "https://staging.tsn.truflation.com",
signerInfo: {
address: wallet.address,
signer: wallet, // Must implement signMessage (e.g. ethers Wallet)
},
chainId,
});
// Create and initialize a primitive stream
const streamId = await StreamId.generate("my-stream");
await client.deployStream(streamId, "primitive", true);
const stream = client.loadPrimitiveStream({
streamId,
dataProvider: client.address(),
});
await stream.initializeStream();
// Insert data
await stream.insertRecords([
{ dateValue: "2024-01-01", value: "100.5" }
]);
// Read data
const data = await stream.getRecord({
dateFrom: "2024-01-01",
dateTo: "2024-01-01"
});
The SDK provides optimized clients for different environments:
// For Node.js
import { NodeTNClient } from "@trufnetwork/sdk-js";
// For browsers
import { BrowserTNClient } from "@trufnetwork/sdk-js";
- Review Core Concepts to understand streams and permissions
- See the API Reference for detailed method documentation
- Check our integration tests for comprehensive examples
For support and issues, please visit our GitHub repository.