BARK Whitepaper
  • Welcome
  • Executive Summary
  • Abstract
  • Disclaimer
  • About
    • The BARK Protocol
      • Business Model
        • Fee Structure
          • Benefits
      • The Vision of BARK
        • Foundation
  • Introduction
    • Transformative Technology
      • Benefits
  • Markets
    • Global Markets
      • Problem
      • Traditional Finance
        • The Role of Bots
        • Solution
        • Resources
  • Solutions
    • Verifiable Web
      • Features
        • Real-World Use Cases
          • Charitable Donation
          • Tokenized Assets
            • Real-World Asset Token
            • CNFT
              • Implementation
        • Asset Marketplace
          • Benefits
          • System Architecture
      • Advantages
    • Technology
      • Architecture
      • Benefits
  • Ecosystem
    • Strategic Planning
    • Introduction
      • BARK
      • Components
        • Governance
          • Voting
          • Participation
            • Getting Started
          • Treasury
            • Advantages
        • Underdogs
          • Development
            • Members Club´s
              • Mission Statement
                • Tiered Members
                • Responsibilities
                  • Services
              • BARKER
                • Membership
                  • Council
              • The Peaky Barkers
                • Mission
                • Brand
                  • Merchandise
              • Sparky Bros
                • Mission
                • Brand
                  • Merchandise
            • Benefits
            • Marketing
            • Participate
            • FAQ
    • Members Club´s
  • Technology
    • Architecture
      • Tokenization
        • Overview
        • BARK
          • Overview
            • Utility
            • Benefits
            • Advantages
        • BPT Token
        • BRWA: Tokenized Assets
        • BARK Protocol Token
          • Integration
    • Token Standard
      • SPL-404
      • Why Solana
  • Product
    • NFT Marketplace
      • Website
      • FAQ
    • Social Finance
      • Introduction
        • CNFT 404
      • Architecture
        • Components
      • Disbursement
        • Architecture
          • User Interface
            • Features
        • Introduction
          • Use Cases
            • Charity
            • Payments
            • Swap
          • Benefits
    • Crowdfunding Platform
      • About
      • Overview
        • Features
          • Components
            • Payments System
        • Benefits
        • Use Cases
        • Compliance
      • Development
        • Overview
          • Website
          • Application
            • Assets
          • Solana
            • Components
            • Programs
          • SUI
            • Components
          • References
        • Brand Guidelines
          • Assets
        • Roadmap
    • Blinks
      • Introduction
      • Components
    • BarkBOT
      • About
      • Features
        • API
          • Example
      • Reguirements
        • Integration
          • Blockchain
          • Programs
      • Architecture
        • Advantages
      • References
    • Commerce
      • Components
        • Backend
          • API
        • Storefront
        • Plugins
          • Payments
            • Payment Gateway
      • References
        • Tutorial
    • BarkSwap
      • Introduction
        • Architecture
        • Features
          • Benefits
    • Staking DApp
    • BARK AI Chatbot
      • Application
        • Development
          • Programs
          • NFT
            • Badges
        • FAQ
      • Architecture
        • Implementation
      • Demo
    • Token Sale Dashboard
      • Terminology
      • Benefits
  • Tokenomics
    • Tokenization
      • BARK
        • BARK (SPL20)
          • Use Cases
          • Distribution
          • Vesting & Locking Mechanism
        • BARK (Token-2022)
          • Specification
            • Important
          • Utility
            • Fees
              • Allocation
            • Staking
          • Distribution
          • Vesting
          • Emission Plan
            • Burning
              • Burning Process
        • CNFT
          • BARKER
            • Information
              • Community Token
            • Allocation
            • Swap
          • SPARKY
            • Token economy
            • Features
      • BPT
      • BRWA
  • Airdop
    • Acknowledgment
    • Overview
      • FAQ
  • Roadmap
    • Comprehensive Strategy
      • Recover & BARK Burning Plan
      • Strategic Transition to SPL-20 Token Standard
    • Milestones
      • Strategy Change
        • Airdrop One
        • Trading
          • Listing Process on DEXs
      • Exchanges
  • Community
    • Future Development
      • Treasury
        • Implementation
    • Overview
      • Governance
        • Specifications
          • Verification
        • Join BARK
      • Rewards
      • Engagement
        • Airdrops
    • FAQ
  • References
    • References
  • Developers
    • Applications
      • Blinks
        • Components
          • UI/UX Design
          • Server
            • Example
        • Actions
          • Frameworks
            • React Native
          • Referrals
          • Donate
          • Swap
          • Extensions
        • API Documentation
          • API
            • Use Cases
            • Features
            • Integration
      • Token Swap System
        • Architecture
          • Sample
          • BarkSwap API
      • BarkPaws Bot
        • Interface
          • Web3 DApp
          • Benefits
          • Improvement
      • Fundraising Platform
        • Introduction
          • Smart Contracts
            • Technical Overview
              • Contract
        • Components
          • Campaigns
            • Payments
              • Payment Processor
              • Stablecoin
                • Escrow Programs
                • Compliance
        • References
          • API
            • Documentation
    • BARK & Jupiter Swap API
      • API
    • Reward System
    • Product Owners
      • Grant Programs
  • Partnership
    • Collaboration
  • Annauncement
    • Newsletter
  • Documentation
    • Projects
      • Market Maker Bot
      • BARKER´s Club
      • Contributing
      • FairLauncher.fun
    • Investors Guide
      • Trading
  • Assets
    • Brand
      • Brand Guide
        • System Design
          • Colors Guide
        • Assets
Powered by GitBook
On this page
  1. Developers
  2. Applications
  3. Blinks
  4. Components

Server

Routing Example:

  • actions/payments/route.ts

  • actions/transactions/route.ts

  • actions/donation/route.ts

  • actions/stake/route.ts

  • actions/vote/route.ts

  • actions/wallet/route.ts

  • actions/settings/route.ts

  • actions/validation/route.ts

Modular routing:

A modular approach to create the required route files for different actions in your Express application. Each file will handle specific routes for actions such as payments, transactions, donations, staking, voting, wallet management, settings, and validation.

Directory Structure (example)

src/
  actions/
    payments/
      route.ts
    transactions/
      route.ts
    donation/
      route.ts
    stake/
      route.ts
    vote/
      route.ts
    wallet/
      route.ts
    settings/
      route.ts
    validation/
      route.ts
  server.ts
  customHandlers.ts

src/actions/payments/route.ts

Handles payments-related actions, e.g., transferring SOL, BARK and USDC.

import express from 'express';
import { Connection, PublicKey, Transaction, Keypair } from '@solana/web3.js';
import { Token, TOKEN_PROGRAM_ID } from '@solana/spl-token';

const router = express.Router();
const connection = new Connection(clusterApiUrl('devnet'));

// Example handler for transferring USDC
router.post('/usdc', async (req, res) => {
  try {
    const { amount, toPubkey } = req.query;
    const { account } = req.body;

    if (!account || !toPubkey || !amount) {
      throw new Error('Missing required parameters');
    }

    const fromPubkey = new PublicKey(account);
    const token = new Token(connection, USDC_MINT_ADDRESS, TOKEN_PROGRAM_ID, Keypair.generate());

    const fromTokenAccount = await token.getOrCreateAssociatedAccountInfo(fromPubkey);
    const toTokenAccount = await token.getOrCreateAssociatedAccountInfo(new PublicKey(toPubkey));

    const transferInstruction = Token.createTransferInstruction(
      TOKEN_PROGRAM_ID,
      fromTokenAccount.address,
      toTokenAccount.address,
      fromPubkey,
      [],
      amount * 1_000_000  // USDC has 6 decimal places
    );

    const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
    const transaction = new Transaction({
      feePayer: fromPubkey,
      blockhash,
      lastValidBlockHeight,
    }).add(transferInstruction);

    // Process the transaction and return response
    res.json({ transaction });
  } catch (err) {
    res.status(400).json({ error: err.message || 'An unknown error occurred' });
  }
});

export default router;

src/actions/transactions/route.ts

Handles transactions-related actions, e.g., transferring SOL.

import express from 'express';
import { Connection, PublicKey, SystemProgram, Transaction } from '@solana/web3.js';

const router = express.Router();
const connection = new Connection(clusterApiUrl('devnet'));

// Handler for transferring SOL
router.post('/sol', async (req, res) => {
  try {
    const { amount, toPubkey } = req.query;
    const { account } = req.body;

    if (!account || !toPubkey || !amount) {
      throw new Error('Missing required parameters');
    }

    const fromPubkey = new PublicKey(account);
    const minimumBalance = await connection.getMinimumBalanceForRentExemption(0);

    if (amount * LAMPORTS_PER_SOL < minimumBalance) {
      throw new Error(`Account may not be rent exempt: ${toPubkey}`);
    }

    const transferSolInstruction = SystemProgram.transfer({
      fromPubkey: fromPubkey,
      toPubkey: new PublicKey(toPubkey),
      lamports: amount * LAMPORTS_PER_SOL,
    });

    const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
    const transaction = new Transaction({
      feePayer: fromPubkey,
      blockhash,
      lastValidBlockHeight,
    }).add(transferSolInstruction);

    // Process the transaction and return response
    res.json({ transaction });
  } catch (err) {
    res.status(400).json({ error: err.message || 'An unknown error occurred' });
  }
});

export default router;

src/actions/donation/route.ts

Handles donation-related actions.

import express from 'express';
import { Connection, PublicKey, SystemProgram, Transaction } from '@solana/web3.js';

const router = express.Router();
const connection = new Connection(clusterApiUrl('devnet'));

// Handler for donating SOL
router.post('/sol', async (req, res) => {
  try {
    const { amount, toPubkey } = req.query;
    const { account } = req.body;

    if (!account || !toPubkey || !amount) {
      throw new Error('Missing required parameters');
    }

    const fromPubkey = new PublicKey(account);
    const transferSolInstruction = SystemProgram.transfer({
      fromPubkey: fromPubkey,
      toPubkey: new PublicKey(toPubkey),
      lamports: amount * LAMPORTS_PER_SOL,
    });

    const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
    const transaction = new Transaction({
      feePayer: fromPubkey,
      blockhash,
      lastValidBlockHeight,
    }).add(transferSolInstruction);

    // Process the donation and return response
    res.json({ transaction });
  } catch (err) {
    res.status(400).json({ error: err.message || 'An unknown error occurred' });
  }
});

export default router;

src/actions/stake/route.ts

Handles staking-related actions.

import express from 'express';
import { Connection, PublicKey, Transaction } from '@solana/web3.js';
import { stakeTokens } from '../customHandlers'; // Replace with actual implementation

const router = express.Router();
const connection = new Connection(clusterApiUrl('devnet'));

// Handler for staking SOL
router.post('/stake', async (req, res) => {
  try {
    const { amount, validator } = req.body;
    const { account } = req.body;

    if (!account || !validator || !amount) {
      throw new Error('Missing required parameters');
    }

    const fromPubkey = new PublicKey(account);
    const validatorPubkey = new PublicKey(validator);

    const transaction = await stakeTokens(connection, fromPubkey, validatorPubkey, amount);

    res.json({ transaction });
  } catch (err) {
    res.status(400).json({ error: err.message || 'An unknown error occurred' });
  }
});

export default router;

src/actions/vote/route.ts

Handles voting-related actions.

import express from 'express';
import { Connection, PublicKey, Transaction } from '@solana/web3.js';
import { voteOnProposal } from '../customHandlers'; // Replace with actual implementation

const router = express.Router();
const connection = new Connection(clusterApiUrl('devnet'));

// Handler for voting on a proposal
router.post('/vote', async (req, res) => {
  try {
    const { proposalId, vote } = req.body;
    const { account } = req.body;

    if (!account || !proposalId || !vote) {
      throw new Error('Missing required parameters');
    }

    const fromPubkey = new PublicKey(account);
    const transaction = await voteOnProposal(connection, fromPubkey, proposalId, vote);

    res.json({ transaction });
  } catch (err) {
    res.status(400).json({ error: err.message || 'An unknown error occurred' });
  }
});

export default router;

src/actions/wallet/route.ts

Handles wallet management-related actions.

import express from 'express';
import { Connection, PublicKey, Transaction } from '@solana/web3.js';
import { manageWallet } from '../customHandlers'; // Replace with actual implementation

const router = express.Router();
const connection = new Connection(clusterApiUrl('devnet'));

// Handler for managing wallet settings
router.post('/manage', async (req, res) => {
  try {
    const { action, parameters } = req.body;
    const { account } = req.body;

    if (!account || !action) {
      throw new Error('Missing required parameters');
    }

    const fromPubkey = new PublicKey(account);
    const transaction = await manageWallet(connection, fromPubkey, action, parameters);

    res.json({ transaction });
  } catch (err) {
    res.status(400).json({ error: err.message || 'An unknown error occurred' });
  }
});

export default router;

src/actions/settings/route.ts

Handles settings-related actions.

import express from 'express';

const router = express.Router();

// Example handler for settings
router.get('/', (req, res) => {
  try {
    // Retrieve settings or configuration data
    res.json({ settings: 'Settings data' });
  } catch (err) {
    res.status(500).json({ error: err.message || 'An unknown error occurred' });
  }
});

export default router;

src/actions/validation/route.ts

Handles validation-related actions.

import express from 'express';

const router = express.Router();

// Example handler for validation
router.post('/validate', (req, res) => {
  try {
    const { data } = req.body;

    if (!data) {
      throw new Error('No data provided for validation');
    }

    // Perform validation logic
    res.json({ validation: 'Data is valid' });
  } catch (err) {
    res.status(400).json({ error: err.message || 'An unknown error occurred' });
  }
});

export default router;

src/server.ts

Integrates

all routes into the Express application.

import express from 'express';
import paymentsRouter from './actions/payments/route';
import transactionsRouter from './actions/transactions/route';
import donationRouter from './actions/donation/route';
import stakeRouter from './actions/stake/route';
import voteRouter from './actions/vote/route';
import walletRouter from './actions/wallet/route';
import settingsRouter from './actions/settings/route';
import validationRouter from './actions/validation/route';

const app = express();
const PORT = 8080;

app.use(express.json());
app.use('/api/payments', paymentsRouter);
app.use('/api/transactions', transactionsRouter);
app.use('/api/donation', donationRouter);
app.use('/api/stake', stakeRouter);
app.use('/api/vote', voteRouter);
app.use('/api/wallet', walletRouter);
app.use('/api/settings', settingsRouter);
app.use('/api/validation', validationRouter);

app.listen(PORT, () => {
  console.log(`Server running on http://localhost:${PORT}`);
});

src/customHandlers.ts

Contains custom logic for some actions, such as staking and voting.

import { Connection, PublicKey, Transaction } from '@solana/web3.js';

export const stakeTokens = async (connection: Connection, fromPubkey: PublicKey, validatorPubkey: PublicKey, amount: number): Promise<Transaction> => {
  // Implement staking logic here
  return new Transaction(); // Replace with actual transaction
};

export const voteOnProposal = async (connection: Connection, fromPubkey: PublicKey, proposalId: string, vote: string): Promise<Transaction> => {
  // Implement voting logic here
  return new Transaction(); // Replace with actual transaction
};

export const manageWallet = async (connection: Connection, fromPubkey: PublicKey, action: string, parameters: any): Promise<Transaction> => {
  // Implement wallet management logic here
  return new Transaction(); // Replace with actual transaction
};

Each of these route files will handle different aspects of the application and will be integrated into the main server file. This approach ensures that the application remains modular and easier to maintain.

PreviousUI/UX DesignNextExample

Last updated 8 months ago