To set up a local development environment for the truf.network, follow these steps:

Prerequisites

Ensure the following tools are installed on your system:

  1. Go: Download and install Go.
  2. Taskfile: Install Taskfile.
  3. Docker Compose: Install Docker Compose.
  4. Python (optional, for running seed scripts): Download Python.
  5. Pandas (optional, for running seed scripts): Install Pandas.

Building Locally

You can build and run the TRUF-Node using Docker Compose or manually.

Using Docker Compose (Recommended)

  1. Clone the TSN repository:
git clone https://github.com/trufnetwork/truf-node.git

cd truf-node
  1. Build and start the TRUF-Node containers:
task compose

This command builds and starts the TRUF-Node in Docker containers with pre-seeded data.

Manual Build and Run

  1. Build the Binary:
task build

This compiles the TRUF-Node binary, which will be located in the .build/ directory.

  1. Run PostgreSQL:

Start PostgreSQL using Docker:

task postgres
  1. Run TRUF-Node:

Start a single-node network:

task kwild
  1. Configure kwil-cli:

Set up kwil-cli to interact with TRUF-Node:

kwil-cli configure

Provide the following values when prompted:

  • Kwil RPC URL: http://localhost:8484
  • Kwil Chain ID: (leave blank)
  • Private Key: (any Ethereum private key)

For testing purposes, you can use the private key 0000000000000000000000000000000000000000000000000000000000000001.

Running the Kwil Gateway (Optional)

The Kwil Gateway (KGW) is a load-balancer with authentication capabilities, enabling data privacy protection for Proof of Authority (POA) Kwil blockchain networks. While not required for development, you can run it locally:

  1. Navigate to the deployments/dev-gateway directory:
cd deployments/dev-gateway
  1. Follow the instructions in the README.md file to set up and run the gateway.

Running the Indexer

The indexer collects and processes data from the TSN-DB. To start the indexer:

task indexer

Access the metrics dashboard at http://localhost:1337/v0/swagger.

Fetching the Genesis File

The genesis file contains the initial configuration for the TSN network. To fetch the latest genesis file:

  1. Ensure you have read access to the repository.
  2. Create a .env file in the root directory, similar to .env.example, and include your GitHub token.
  3. Run the following command:
task get-genesis

System Contract

The system contract stores accepted streams by TSN governance and serves as an entry point for queries.

Fetching Records via System Contract

To fetch records:

kwil-cli database call -a=get_unsafe_record -n=tsn_system_contract -o=<owner_address> stream_id:<stream_id> date_from:2024-06-01 date_to:2024-06-17 --private-key <private_key> --provider <provider_url>

This command retrieves records from the system contract for the specified stream and data provider within the given date range.

Metrics and Monitoring

When running the development setup using task compose-dev, the following monitoring tools are available:

  • Prometheus: Accessible at http://localhost:9090
  • Grafana: Accessible at http://localhost:3000 (default credentials: admin/admin)

These tools provide insights into the performance and behavior of the TSN-DB system.

For more details on metrics configuration, refer to the files in the deployments/dev-gateway directory.

Additional Resources

For further assistance, join our Discord community or open an issue on our GitHub repository.