The truf.network provides multiple ways to consume its data. Developers can integrate with the network using SDKs, direct API calls, or predefined API endpoints. Here’s how to get started:

1. SDKs

The truf.network offers SDKs for various programming languages, simplifying integration with its services.

  • Installation: To get started, install the SDK for your language. For example, in Go:
  go get github.com/trufnetwork/sdk-go
  • Usage: Use the SDK to interact with the network. Example in Go:
package main



import (

	"context"

	"fmt"

	"github.com/golang-sql/civil"

	"github.com/kwilteam/kwil-db/core/crypto"

	"github.com/kwilteam/kwil-db/core/crypto/auth"

	"github.com/trufnetwork/sdk-go/core/tsnclient"

	"github.com/trufnetwork/sdk-go/core/types"

	"github.com/trufnetwork/sdk-go/core/util"

)



func main() {

	ctx := context.Background()



	// Create TSN client

	pk, _ := crypto.Secp256k1PrivateKeyFromHex("<your-private-key-hex>")

	signer := &auth.EthPersonalSigner{Key: *pk}

	tsnClient, err := tsnclient.NewClient(ctx, "https://staging.tsn.truflation.com", tsnclient.WithSigner(signer))

	if err != nil {

		panic(err)

	}



	// Load an existing stream

	streamId := util.GenerateStreamId("your-stream-name")

	// if we intend to use streams from another provider, we create locators using the provider's address

	streamLocator := tsnClient.OwnStreamLocator(streamId)

	stream, err := tsnClient.LoadPrimitiveStream(streamLocator)

	if err != nil {

		panic(err)

	}



	// Read data from the stream

	dateFrom, _ := civil.ParseDate("2023-01-01")

	dateTo, _ := civil.ParseDate("2023-01-31")

	records, err := stream.GetRecord(ctx, types.GetRecordInput{

		DateFrom: &dateFrom,

		DateTo:   &dateTo,

	})

	if err != nil {

		panic(err)

	}



	for _, record := range records {

		fmt.Println(record.DateValue, record.Value.String())

	}

}

For more details, refer to the SDK Documentation.