Skip to content

A new FRAME-based Substrate node, ready for hacking.

License

Notifications You must be signed in to change notification settings

zeel991/UseOnce-Pallet-Demo

 
 

Repository files navigation

UseOnce Pallet - Ticket Management System on Substrate

Substrate Version Rust Version

A blockchain-based ticket management system implementing single-use tickets with state transitions controlled through authorized accounts.

Overview 📖

This Substrate pallet (useonce) provides a secure framework for:

  • Immutable ticket registration on-chain
  • Role-based access control for state modifications
  • Final state transition to prevent replay attacks

Key Features 🔑

  • On-Chain Ticket Registry
    Permanent record of all ticket issuances with cryptographic proof
  • Granular Authorization
    Multi-level account privileges using Substrate's origin system
  • State Machine Enforcement
    Strict lifecycle: RegisteredConsumed (with audit trail)
  • Light Client Compatible
    Designed for easy integration with frontend applications

Technical Architecture 🧠

pub enum TicketState {
    Registered,  // Initial state
    Consumed     // Terminal state
}

impl<T: Config> Pallet<T> {
    // Core state transition logic
    fn consume_ticket(ticket_id: T::Hash) -> DispatchResult {
        // Authorization checks
        // State validation
        // Immutable update
    }
}

Installation 🛠️

Prerequisites

  • Rust 1.68+ (rustup install stable)
  • Node.js 16.x+ (LTS recommended)

Node Setup

# Clone repository
git clone https://github.com/zeel991/substrate-node-template.git
cd substrate-node-template

# Build optimized binary
cargo build --release --features runtime-benchmarks

# Launch development node
./target/release/node-template \
  --dev \
  --base-path /tmp/node \
  --ws-port 9944

Frontend Demo Setup (Separate Terminal)

cd substrate-demo

# Install dependencies
yarn build

# Start interactive demo
yarn demo 

Usage Examples 💻

1. Issue New Ticket (Sudo)

const ticketId = api.createType('Hash', crypto.randomBytes(32));
await api.tx.useOnce.createTicket(ticketId).signAndSend(alice);

2. Consume Ticket (Authorized Account)

const stateUpdate = api.tx.useOnce.consumeTicket(ticketId);
await stateUpdate.signAndSend(authorizedBob, { nonce: currentNonce });

3. Verify Ticket State

const ticket = await api.query.useOnce.tickets(ticketId);
console.log(`Ticket ${ticketId.toHex()} state: ${ticket.state.toString()}`);

Testing 🧪

Run comprehensive test suite:

# Unit tests
cargo test -p useonce-pallet

# Integration tests
cargo test --test integration

Security Model 🔒

  • Authorization: Only pre-approved accounts can modify state
  • Finality: Once consumed, tickets cannot be reverted
  • Nonce Protection: Replay attack prevention through transaction numbering

About

A new FRAME-based Substrate node, ready for hacking.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 83.4%
  • JavaScript 8.7%
  • TypeScript 3.8%
  • Nix 2.4%
  • Dockerfile 1.3%
  • Shell 0.4%