The TN SDK provides developers with tools to interact with the Truf Network, a decentralized platform for publishing, composing, and consuming economic data streams.
- Node.js 18 or later
npm install @trufnetwork/sdk-js
# or your preferred package manager
// For Node.js applications
import { NodeTNClient } from "@trufnetwork/sdk-js";
// For browser applications
import { BrowserTNClient } from "@trufnetwork/sdk-js";
import { NodeTNClient, StreamId } from "@trufnetwork/sdk-js";
// Initialize client
const client = new NodeTNClient({
endpoint: "https://staging.tsn.truflation.com",
signerInfo: {
address: wallet.address,
signer: wallet, // Any object that implements signMessage
},
chainId: "tsn-1", // or use NodeTNClient.getDefaultChainId()
});
// Deploy and initialize a stream
const streamId = await StreamId.generate("my-data-stream");
await client.deployStream(streamId, "primitive", true);
const stream = client.loadPrimitiveStream({
streamId,
dataProvider: client.address(),
});
// here simplified, you might need to wait for the tx using client.waitForTx
await stream.initializeStream();
// Insert data, simplified
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",
});
For a complete working example:
- Check our TN SDK Demo Repository
- Try the Live Demo on CodeSandbox
- Try reading from a Truflation Stream on CodeSandbox with NodeJS
TN supports two main types of streams:
- Primitive Streams: Direct data sources from providers
- Composed Streams: Aggregate data from multiple streams using weights
More information about TN components can be found in the Js TN-SDK Documentation.
A staging network is available at https://staging.tsn.truflation.com for testing and experimentation.
This package works with Deno when using the --allow-net
permission flag:
import { ... } from "npm:@trufnetwork/sdk-js"
By default, some dependencies requires environment permissions. If you need to run without environment permissions, please see this GitHub issue for workarounds.
For support, please open an issue.
Licensed under the Apache License, Version 2.0. See LICENSE for details.