Beginner's Guide

TELA Beginner Guide

Complete beginner's guide to TELA development - from setup to your first deployed application.

🎯

Goal: By the end of this guide, you'll have a working TELA application deployed on the DERO blockchain!

What You'll Learn

  1. What TELA is and why it's revolutionary
  2. Setting up your development environment
  3. Creating your first TELA application
  4. Deploying to the DERO blockchain
  5. Testing your deployed application

What is TELA?

TELA is a platform for building truly private web3 applications that run on the DERO blockchain.

Key Differences from Traditional Web Development

Traditional WebTELA Applications
Hosted on serversStored on blockchain
CentralizedDecentralized
Privacy concernsComplete privacy
Server dependenciesNo external dependencies
Can be censoredCensorship resistant

Why TELA Matters

  • πŸ”’ Complete Privacy: Built on DERO's homomorphic encryption
  • 🌐 True Decentralization: No servers, no single points of failure
  • ⚑ Local Performance: Apps run locally for maximum speed
  • πŸ›‘οΈ Censorship Resistant: Cannot be taken down or blocked
  • πŸ’° Cost Effective: Pay once to deploy, run forever

Development Environment Setup

Prerequisites

  1. DERO Wallet (Engram recommended for beginners)

  2. TELA-CLI (for deployment)

  3. Code Editor (VS Code, Sublime, etc.)

    • Any text editor will work
    • Syntax highlighting for JavaScript/HTML/CSS helpful
  4. Web Browser (Chrome, Firefox, Safari, Edge)

    • For testing your applications
    • Developer tools for debugging

Verify Setup

# Check TELA-CLI installation
tela-cli --version
 
# Check DERO wallet is running
# Engram: Look for XSWD status in wallet
# CLI: Should show "RPC server started" message

Your First TELA Application

Let's create a simple "Hello TELA" application that displays DERO network information.

Step 1: Create HTML File

Create hello-tela.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hello TELA</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, sans-serif;
            background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
            color: #ffffff;
            margin: 0;
            padding: 20px;
            min-height: 100vh;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .card {
            background: rgba(255, 255, 255, 0.05);
            border: 1px solid rgba(255, 255, 255, 0.1);
            border-radius: 12px;
            padding: 20px;
            margin-bottom: 20px;
        }
        .status {
            padding: 8px 16px;
            border-radius: 6px;
            font-weight: 500;
            margin-bottom: 10px;
        }
        .status.connected { background: #28a745; }
        .status.connecting { background: #ffc107; color: #000; }
        .status.error { background: #dc3545; }
        .btn {
            background: #52c8db;
            color: #000;
            border: none;
            padding: 10px 20px;
            border-radius: 6px;
            cursor: pointer;
            font-weight: 600;
            margin: 5px;
        }
        .btn:hover { background: #45a8b8; }
    </style>
</head>
<body>
    <div class="container">
        <h1>πŸš€ Hello TELA!</h1>
        <p>Your first TELA application running on DERO blockchain</p>
        
        <div class="card">
            <h2>Connection Status</h2>
            <div id="connection-status" class="status connecting">Connecting...</div>
            <button class="btn" onclick="connectToXSWD()">Connect to DERO</button>
        </div>
        
        <div class="card">
            <h2>DERO Network Information</h2>
            <div id="network-info">
                <p>Connect to DERO to see network information</p>
            </div>
            <button class="btn" onclick="loadNetworkInfo()">Refresh Data</button>
        </div>
        
        <div class="card">
            <h2>Your Wallet</h2>
            <div id="wallet-info">
                <p>Connect to see your wallet information</p>
            </div>
            <button class="btn" onclick="loadWalletInfo()">Load Wallet Data</button>
        </div>
    </div>
    
    <script src="hello-tela.js"></script>
</body>
</html>

Step 2: Create JavaScript File

Create hello-tela.js:

// Hello TELA - Your first TELA application
({
    name: 'hello-tela',
    version: '1.0.0',
    
    // Connection state
    socket: null,
    connected: false,
    
    // Initialize the application
    init: function() {
        console.log('πŸš€ Hello TELA initializing...');
        this.updateStatus('connecting', 'Initializing...');
    },
    
    // Connect to XSWD
    connectXSWD: function() {
        var self = this;
        
        try {
            self.updateStatus('connecting', 'Connecting to DERO...');
            
            // Application identification
            var appData = {
                "id": "hello-tela-app-v1",
                "name": "Hello TELA",
                "description": "My first TELA application",
                "url": window.location.origin
            };
            
            // Create WebSocket connection
            self.socket = new WebSocket("ws://127.0.0.1:44326/xswd");
            
            self.socket.onopen = function() {
                console.log('πŸ”— WebSocket opened, sending handshake...');
                self.socket.send(JSON.stringify(appData));
            };
            
            self.socket.onmessage = function(event) {
                var response = JSON.parse(event.data);
                
                if (response.accepted) {
                    self.connected = true;
                    self.updateStatus('connected', 'Connected to DERO!');
                    console.log('βœ… XSWD connection accepted');
                    
                    // Automatically load initial data
                    self.loadNetworkInfo();
                } else if (response.jsonrpc) {
                    self.handleAPIResponse(response);
                }
            };
            
            self.socket.onclose = function() {
                self.connected = false;
                self.updateStatus('error', 'Connection closed');
                console.log('πŸ”Œ XSWD connection closed');
            };
            
            self.socket.onerror = function(error) {
                self.updateStatus('error', 'Connection failed');
                console.error('🚨 XSWD connection error:', error);
            };
            
        } catch (error) {
            self.updateStatus('error', 'Connection error: ' + error.message);
            console.error('Failed to connect:', error);
        }
    },
    
    // Handle API responses
    handleAPIResponse: function(response) {
        // This is where we'll handle API call responses
        console.log('πŸ“₯ API Response:', response);
    },
    
    // Update connection status display
    updateStatus: function(status, message) {
        var statusEl = document.getElementById('connection-status');
        if (statusEl) {
            statusEl.className = 'status ' + status;
            statusEl.textContent = message;
        }
    },
    
    // Make API calls
    call: function(method, params) {
        var self = this;
        
        if (!self.connected) {
            throw new Error('Not connected to XSWD');
        }
        
        return new Promise(function(resolve, reject) {
            var id = Math.random().toString(36);
            var request = {
                "jsonrpc": "2.0",
                "method": method,
                "id": id,
                "params": params || {}
            };
            
            // Store request for response handling
            self.pendingRequests = self.pendingRequests || {};
            self.pendingRequests[id] = { resolve: resolve, reject: reject };
            
            // Send request
            self.socket.send(JSON.stringify(request));
            
            // Timeout after 30 seconds
            setTimeout(function() {
                if (self.pendingRequests[id]) {
                    delete self.pendingRequests[id];
                    reject(new Error('Request timeout'));
                }
            }, 30000);
        });
    },
    
    // Load network information
    loadNetworkInfo: function() {
        var self = this;
        
        if (!self.connected) {
            alert('Please connect to DERO first');
            return;
        }
        
        console.log('πŸ“Š Loading network information...');
        
        self.call('DERO.GetInfo').then(function(info) {
            self.displayNetworkInfo(info);
        }).catch(function(error) {
            console.error('Failed to load network info:', error);
            alert('Failed to load network information: ' + error.message);
        });
    },
    
    // Display network information
    displayNetworkInfo: function(info) {
        var html = '<h3>πŸ“Š Network Statistics</h3>';
        html += '<p><strong>Block Height:</strong> ' + info.height.toLocaleString() + '</p>';
        html += '<p><strong>Difficulty:</strong> ' + info.difficulty.toLocaleString() + '</p>';
        html += '<p><strong>Hash Rate:</strong> ' + (info.hashrate / 1000000).toFixed(2) + ' MH/s</p>';
        html += '<p><strong>Connected Peers:</strong> ' + info.peer_count + '</p>';
        html += '<p><strong>Pending Transactions:</strong> ' + info.tx_pool_size + '</p>';
        html += '<p><strong>Network Version:</strong> ' + info.version + '</p>';
        
        var container = document.getElementById('network-info');
        if (container) {
            container.innerHTML = html;
        }
    },
    
    // Load wallet information
    loadWalletInfo: function() {
        var self = this;
        
        if (!self.connected) {
            alert('Please connect to DERO first');
            return;
        }
        
        console.log('πŸ’° Loading wallet information...');
        
        // Get wallet address
        self.call('GetAddress').then(function(addressResult) {
            // Get wallet balance
            return self.call('GetBalance').then(function(balanceResult) {
                self.displayWalletInfo(addressResult.address, balanceResult);
            });
        }).catch(function(error) {
            console.error('Failed to load wallet info:', error);
            alert('Failed to load wallet information: ' + error.message);
        });
    },
    
    // Display wallet information
    displayWalletInfo: function(address, balance) {
        var html = '<h3>πŸ’° Your Wallet</h3>';
        html += '<p><strong>Address:</strong> ' + address.substring(0, 20) + '...</p>';
        html += '<p><strong>Balance:</strong> ' + (balance.unlocked_balance / 100000).toFixed(5) + ' DERO</p>';
        html += '<p><strong>Locked Balance:</strong> ' + ((balance.balance - balance.unlocked_balance) / 100000).toFixed(5) + ' DERO</p>';
        
        var container = document.getElementById('wallet-info');
        if (container) {
            container.innerHTML = html;
        }
    }
});
 
// Global functions for HTML onclick handlers
window.connectToXSWD = function() {
    if (window.HelloTELA) {
        window.HelloTELA.connectXSWD();
    }
};
 
window.loadNetworkInfo = function() {
    if (window.HelloTELA) {
        window.HelloTELA.loadNetworkInfo();
    }
};
 
window.loadWalletInfo = function() {
    if (window.HelloTELA) {
        window.HelloTELA.loadWalletInfo();
    }
};
 
// Initialize when page loads
window.addEventListener('load', function() {
    // Make module available globally
    window.HelloTELA = window.HelloTELA || arguments[0];
    
    if (window.HelloTELA) {
        window.HelloTELA.init();
    }
});

πŸ“‹ Step-by-Step Deployment

Step 1: Test Locally

  1. Start a local web server:

    # In your project directory
    python3 -m http.server 8080
    # Or use any local web server
  2. Open in browser: http://localhost:8080/hello-tela.html

  3. Test functionality:

    • Click "Connect to DERO"
    • Approve connection in wallet
    • Click "Refresh Data" to load network info
    • Click "Load Wallet Data" to see your balance

Step 2: Deploy to DERO Blockchain

  1. Deploy the HTML file:

    tela-cli install-doc
    # Enter file path: ./hello-tela.html
    # Enter name: Hello TELA App
    # Enter description: My first TELA application
    # Enter dURL: hello-tela-app
    # Note the SCID (e.g., abc123...)
  2. Deploy the JavaScript file:

    tela-cli install-doc
    # Enter file path: ./hello-tela.js
    # Enter name: Hello TELA Logic
    # Enter description: Application logic for Hello TELA
    # Enter dURL: hello-tela-logic
    # Note the SCID (e.g., def456...)
  3. Create application index:

    tela-cli install-index
    # Enter name: Hello TELA Application
    # Enter description: Complete Hello TELA application
    # Enter dURL: hello-tela
    # DOC1: abc123... (HTML SCID)
    # DOC2: def456... (JS SCID)
    # Note the INDEX SCID (e.g., ghi789...)

Step 3: Test Deployed Application

  1. Serve the application:

    tela-cli serve ghi789...
    # Application will be available at http://localhost:8082
  2. Test in browser: Open http://localhost:8082

  3. Verify functionality: Same as local testing

πŸŽ‰

Congratulations! You've just deployed your first TELA application to the DERO blockchain!

Understanding the Code

Object Literal Pattern

// βœ… TELA uses this pattern for all modules
({
    name: 'my-app',
    version: '1.0.0',
    
    // Properties and methods go here
    myMethod: function() {
        // Function logic
    }
});

Why this pattern?

  • βœ… Deployment Success: 100% success rate with DERO blockchain
  • βœ… Self-Contained: All functionality in one object
  • βœ… No External Dependencies: Everything needed is included

XSWD Integration

// XSWD connection flow
connectXSWD: function() {
    // 1. Create WebSocket connection
    this.socket = new WebSocket("ws://127.0.0.1:44326/xswd");
    
    // 2. Send application identification
    this.socket.onopen = function() {
        this.socket.send(JSON.stringify(appData));
    };
    
    // 3. Handle wallet approval
    this.socket.onmessage = function(event) {
        var response = JSON.parse(event.data);
        if (response.accepted) {
            // Connection approved!
        }
    };
}

API Calls

// Making blockchain API calls
call: function(method, params) {
    return new Promise(function(resolve, reject) {
        var request = {
            "jsonrpc": "2.0",
            "method": method,
            "id": "unique-id",
            "params": params
        };
        
        // Send request and handle response
        this.socket.send(JSON.stringify(request));
    });
}

Next Steps

Enhance Your Application

  1. Add More Features:

    // Add mining capability
    startMining: function() {
        return this.call('AttemptEPOCH', { hashes: 1000 });
    },
     
    // Add transaction history
    loadTransactions: function() {
        return this.call('GetTransfers', { in: true, out: true });
    }
  2. Improve the UI:

    • Add loading indicators
    • Better error handling
    • Responsive design
    • Dark/light theme toggle
  3. Add Smart Contract Integration:

    // Interact with smart contracts
    loadContract: function(scid) {
        return this.call('DERO.GetSC', { 
            scid: scid, 
            variables: true 
        });
    }

Explore Advanced Features

  1. TELA Libraries - Use reusable code components
  2. Design System - Professional UI patterns
  3. EPOCH Mining - Add mining functionality
  4. Advanced API - Explore all available methods

🚨 Common Beginner Mistakes

Mistake 1: Using Modern JavaScript

// ❌ DON'T USE - ES6+ syntax not supported
const myFunction = () => {};
async function getData() {}
let variable = 'value';
 
// βœ… USE INSTEAD - Traditional JavaScript
var myFunction = function() {};
function getData() { return promise; }
var variable = 'value';

Mistake 2: External Dependencies

<!-- ❌ DON'T USE - External resources -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter" rel="stylesheet">
 
<!-- βœ… USE INSTEAD - Local resources only -->
<script src="my-chart-lib.js"></script>
<style>
    body { font-family: system-ui, sans-serif; }
</style>

Mistake 3: File Size Violations

# ❌ File too large
$ wc -c hello-tela.js
25000 hello-tela.js  # 25KB - too large!
 
# βœ… Optimize file size
$ wc -c hello-tela.js  
15000 hello-tela.js  # 15KB - perfect!

Mistake 4: Improper Error Handling

// ❌ Poor error handling
function loadData() {
    xswd.call('DERO.GetInfo'); // No error handling
}
 
// βœ… Proper error handling
function loadData() {
    xswd.call('DERO.GetInfo')
        .then(function(info) {
            // Handle success
        })
        .catch(function(error) {
            console.error('API call failed:', error);
            // Show user-friendly error
        });
}

πŸ“š Learning Resources

Essential Reading

  1. TELA-CLI Guide - Command-line interface
  2. API Reference - All available methods
  3. Compliance Rules - Deployment requirements

Video Tutorials

  • DERO community YouTube channel
  • TELA development streams
  • Blockchain development basics

Example Applications

  • Block Explorer - Browse DERO blockchain
  • Mining Dashboard - EPOCH mining interface
  • Wallet Interface - Balance and transaction management
  • Smart Contract Browser - Explore deployed contracts
πŸŽ“

Learning Path: Start with this beginner guide, then explore the Complete API Guide, and finally dive into Advanced TELA Features when you're ready to build more complex applications.

Your TELA Journey

  1. βœ… Complete this tutorial - Deploy your first app
  2. πŸ“š Study the API docs - Learn all available methods
  3. 🎨 Apply design patterns - Make it look professional
  4. πŸš€ Build something amazing - Create your unique application
  5. 🌟 Share with community - Help others learn TELA

Welcome to TELA development! You're now part of building the future of private, decentralized web applications on the DERO blockchain.