Welcome to the VIA Project Node documentation. This guide outlines how to install the VIA Project Node, how to develop and integrate custom features, and where to seek additional help.
The package also contains an optional Express server which exposes an API for events that can be consumed by the DataStreamClient
. The DataStreamClient
example can be found in the client-stream-example repository, and an optional Discord integration.
Ensure your system meets the following specifications to successfully install and run the VIA Project Node:
- Operating System: Any OS that supports Docker
- Memory: Minimum of 1GB RAM
- CPU: At least 1 CPU core
- Network: Stable internet connection
-
Clone the Repository: First, clone the repository to your local machine:
git clone https://github.com/VIALabs-io/node-project.git cd node-project
-
Create and Update the
.env
File: Create a.env
file in the project root by copying the.env.example
file:cp .env.example .env
Open the
.env
file and update the necessary environment variables:NODE_PRIVATE_KEY
: This is a critical environment variable that should be set to your node's private key. It is required for the application to function correctly.NODE_PUBLIC_KEY
: Set this to your node's public key for the provided private key.DATA_STREAM_PORT
: This is the port that the optionalDataStreamServer
will use. If not specified, it will not be started.
Example
.env
file configuration:DEBUG=true NODE_ENV=development NODE_PRIVATE_KEY=your_private_key_here NODE_PUBLIC_KEY=your_public_key_here DATA_STREAM_PORT=3000
-
Build the Docker Image: Build the Docker image using the following command:
docker build -t vialabs-node .
-
Run the Docker Container in Development Mode: Run the container using the command below:
docker run --env-file .env -p 3000:3000 vialabs-node
The application will start in development mode as specified by
NODE_ENV=development
in your.env
file.If
DATA_STREAM_PORT
is set, theDataStreamServer
will be automatically started.
The DataStreamClient
package allows you to connect to a real-time data stream from the P2P validation network. This is particularly useful for clients or services that need to react to or process real-time events as they occur in the network.
The DataStreamClient
example can be found in the client-stream-example repository.
import { DataStreamClient } from '@vialabs-io/node-core/DataStreamClient';
// Create a new instance of DataStreamClient (run local node or point to external node)
const client = new DataStreamClient('http://localhost:3000');
// Connect to the server
client.connect(
(message) => {
// Handle incoming message
console.log('Received message:', message);
},
() => {
// On connect callback
console.log('Connected to server');
},
() => {
// On disconnect callback
console.log('Disconnected from server');
}
);
The VIA Project Node offers an optional integration with Discord, allowing you to receive real-time logs of events in a specified Discord channel and interact with the node through bot commands in a dedicated command channel.
-
Visit the Discord Developer Portal: Go to the Discord Developer Portal and log in with your Discord account.
-
Create a New Application:
- Click on the "New Application" button.
- Provide a name for your application (e.g., "VIA Project Node Bot") and click "Create".
-
Enable the Bot:
- Navigate to the "Bot" tab on the left sidebar.
- Click the "Add Bot" button, and confirm by clicking "Yes, do it!".
- You can optionally customize your bot's avatar and username.
-
Retrieve Bot Credentials:
- Token: Under the "Bot" tab, click the "Copy" button under "Token" to copy your bot's token. You’ll need this for your
.env
file. - Client ID: Navigate to the "OAuth2" tab and copy the "Client ID". You’ll also need this for your
.env
file.
- Token: Under the "Bot" tab, click the "Copy" button under "Token" to copy your bot's token. You’ll need this for your
-
Generate an OAuth2 URL:
- Under the "OAuth2" tab, scroll down to "OAuth2 URL Generator".
- Select the "bot" scope.
- Under "Bot Permissions", select the following permissions:
Read Messages/View Channels
Send Messages
Manage Messages
(optional, for clearing bot's messages)Use Slash Commands
(if you plan to use the command channel)
-
Invite the Bot:
- Copy the generated URL and paste it into your browser.
- Select the server where you want to add the bot and authorize it.
Add the following environment variables to your .env
file to enable Discord integration:
# OPTIONAL: Discord Bot Integration
DISCORD_TOKEN=your_discord_bot_token_here
DISCORD_CLIENT_ID=your_discord_client_id_here
DISCORD_CHANNEL_ID=your_discord_channel_id_here
DISCORD_COMMAND_CHANNEL_ID=your_discord_command_channel_id_here
DISCORD_TOKEN
: The token for your Discord bot (copied from the Discord Developer Portal).DISCORD_CLIENT_ID
: The Client ID of your Discord application.DISCORD_CHANNEL_ID
: The ID of the Discord channel where the bot will log real-time events.DISCORD_COMMAND_CHANNEL_ID
: (Optional) The ID of the Discord channel where the bot will listen for and respond to commands.
Custom features allow the node to interact with off-chain systems, APIs, or process offline data. Features are not needed for basic functionality, they are only required to provide additional deeper integrations with off-chain functionality.
These optional features and can be developed as follows:
- Location: Custom features should reside in the
features/
directory. - Interface: Each feature must extend the
IFeature
interface which defines standard methods for feature interaction.
-
Implement the IFeature Interface: Create a new feature class that implements the
IFeature
interface. Here is theIFeature
interface definition:import { IDriverBase } from "./IDriverBase.js"; import { IMessage } from "./IMessage.js"; export interface IFeature { featureId: number; featureName: string; featureDescription: string; process(driver: IDriverBase, message: IMessage): Promise<IMessage>; isMessageValid(driver: IDriverBase, message: IMessage): Promise<boolean>; }
-
Feature Implementation: Develop the feature logic within the methods defined by
IFeature
. Here’s an example of a simple feature implementation:import { IFeature } from '@vialabs-io/node-core/types/IFeature'; import { IDriverBase } from '@vialabs-io/node-core/types/IDriverBase'; import { IMessage } from '@vialabs-io/node-core/types/IMessage'; class CustomFeature implements IFeature { public featureId = 7000000; // This is normally the correct feature ID to use in a custom project. public featureName = 'CustomFeature'; public featureDescription = 'A custom feature that does something special.'; async process(driver: IDriverBase, message: IMessage): Promise<IMessage> { console.log('Processing feature:', this.featureName); // Custom logic here, pull information from external database, call an API // or do multiple cross chain transactions. Any arbitrary code can run here // and any arbitrary data can be passed back to the receiving contract: // // It is also possible to encode complex data structures, which are decoded // on chain and able to be used by the implementing contract: // // message.featureReply = ethers.utils.defaultAbiCoder.encode(); return message; } async isMessageValid(driver: IDriverBase, message: IMessage): Promise<boolean> { // Optional extra validation logic here - for example, off-chain KYC check or linking to // an off-chain database record or authentication service. return true; } } export default CustomFeature;
To automatically load features, create your feature modules in the src/features
directory. Ensure they are exported from the src/features/index.ts
file. For example:
import CustomFeature from "./CustomFeature.js";
export default [new CustomFeature()];
For further assistance, feature requests, or contributions:
- Email: Contact us at [email protected].
- GitHub: Visit our GitHub repository to report issues or contribute to the project.