Startrix Task is a multi-component project consisting of a backend API, a CLI tool, a frontend application, and a blockchain node. It is designed to demonstrate a blockchain-based wallet system with a modern web interface and command-line utilities.
The project is organized into the following directories:
backend-blockchain/
: A Go-based backend API built with Fiber.cli/
: A command-line interface (CLI) tool built with Cobra for managing wallets.frontend/
: A React-based frontend application built with Next.js.
This is a RESTful API built with the Fiber framework. It provides endpoints for managing transactions, querying balances, and performing airdrops in a blockchain-like system. The API is configured to run on port 3000
.
- URL:
/transaction
- Method:
POST
- Description: Verifies and records a transaction between two accounts.
- Request Body:
{ "sender": "string", // Hex-encoded public key of the sender "recipient": "string", // Address of the recipient "amount": 100.0, // Amount to transfer "signature": "string", // Base64-encoded signature "previous_block": "string" // (Optional) Previous block hash }
- Responses:
200 OK
: Transaction verified and recorded.400 Bad Request
: Invalid JSON or insufficient balance.401 Unauthorized
: Invalid signature.
- URL:
/balance/:address
- Method:
GET
- Description: Retrieves the balance of a specific account.
- Path Parameter:
address
(string): The address of the account.
- Responses:
200 OK
: Returns the balance of the account.{ "address": "string", "balance": 100.0 }
- URL:
/transactions
- Method:
GET
- Description: Retrieves the entire transaction history.
- Responses:
200 OK
: Returns a list of all transactions.[ { "sender": "string", "recipient": "string", "amount": 100.0, "signature": "string", "previous_block": "string" } ]
- URL:
/transactions/:address
- Method:
GET
- Description: Retrieves all transactions associated with a specific address (as sender or recipient).
- Path Parameter:
address
(string): The address to filter transactions by.
- Responses:
200 OK
: Returns a list of transactions associated with the address.{ "transactions": [ { "sender": "string", "recipient": "string", "amount": 100.0, "signature": "string", "previous_block": "string" } ] }
- URL:
/airdrop
- Method:
POST
- Description: Adds 100 coins to the balance of a specified account.
- Request Body:
{ "address": "string" // Address to receive the airdrop }
- Responses:
200 OK
: Airdrop successful.{ "message": "Airdropped 100 coins", "address": "string", "balance": 200.0 }
400 Bad Request
: Invalid request body.
- Transaction Verification: Transactions are verified using Ed25519 signatures. The sender's public key, recipient address, amount, and signature are validated to ensure authenticity.
- Genesis Block: The system initializes with a genesis block to establish the blockchain structure.
- Concurrency: Mutex locks are used to ensure thread-safe operations on shared resources like transaction history and account balances.
- RESTful API built with Fiber.
- Example endpoint:
GET /
returns a "Hello, Fiber!" message. - Configured to run on port
3000
. - Connects to the blockchain node for transaction validation.
-
Navigate to the
backend-blockchain
directory:cd backend-blockchain
-
Build the backend binary:
go build -o backend-server main.go
This will generate an executable file named
backend-server
. -
Run the binary:
./backend-server
The cli
directory contains the command-line interface (CLI) implementation for interacting with the application. This CLI allows users to perform various operations such as creating wallets and managing tasks.
Ensure you have the following installed on your system:
- Go (version 1.16 or later)
-
Navigate to the CLI directory
Change your working directory to thecli
folder where the CLI source code is located. -
Build the CLI binary
Use thego build
command to compile the CLI source code into an executable binary. The output binary will be namedwallet-cli
. -
Execute CLI commands
Run the generated binary to execute commands. For example, you can create a new wallet using thecreateWallet
command.
- Install Startrix-AI Binary (Linux)
If you are using Linux, you can install thestartrix-ai
binary by running:This will allow you to use thesudo install -m 755 wallet-cli /usr/local/bin/startrix-ai
startrix-ai
command globally.
- Ensure the
cli
directory contains themain.go
file, which serves as the entry point for the CLI application. - The
wallet-cli
binary must have execute permissions. If not, you can grant permissions using:chmod +x wallet-cli
- Refer to the application's documentation or source code for additional commands and their usage.
The API will be available at `http://localhost:3000`. """ This module provides functionality for creating and managing cryptocurrency wallets, as well as signing transactions. It includes the following key functions: Functions: ---------- - createWallet(): Creates a new cryptocurrency wallet. This function generates a new private key and derives the corresponding public key and wallet address. The wallet can be used to send and receive cryptocurrency transactions. ### Example: Create Wallet To create a new wallet using the `startrix-cli`, run the following command: ```bash startrix-cli createWallet ``` This will generate a new wallet with a unique address and private key. The output will look similar to: ```plaintext Wallet created successfully! Address: 0x123456789abcdef Private Key: abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890 ``` Make sure to securely store the private key, as it is required to sign transactions. - signTransaction(transaction, privateKey): Signs a cryptocurrency transaction using the provided private key. This ensures the authenticity and integrity of the transaction. The function takes the transaction data and the private key as input, and returns the signed transaction. Other Commands: --------------- - Additional helper functions or utilities may be included in the module to support wallet creation and transaction signing, such as key generation, address derivation, and cryptographic operations. """
-
Navigate to the
frontend
directory:cd frontend
-
Install dependencies:
npm install
-
Run the development server:
npm run dev
The frontend will be available at
http://localhost:3001
.
backend/
: Contains the Go backend code (Fiber API).cli/
: Contains the Go CLI tool for managing wallets.frontend/
: Contains the React frontend code (Next.js).blockchain/
: Contains the blockchain node code that validates transactions and manages the blockchain.README.md
: Documentation for the project.
This project is licensed under the MIT License - see the LICENSE file for details.