This example demonstrates the full Lumera SDK workflow in a browser environment with Keplr wallet integration.
This interactive web application showcases:
- Keplr Wallet Connection: Seamless integration with the Keplr browser extension
- Blockchain Queries: Real-time queries to the Lumera testnet
- File Upload: Upload files to Cascade distributed storage
- File Download: Download and verify files from Cascade storage
- Progress Tracking: Visual feedback for all operations
- Activity Logging: Real-time activity log for debugging and transparency
- Node.js 18+ - Required for building the example
- Keplr Browser Extension - Install from keplr.app
- Lumera Testnet Tokens - Ensure your Keplr wallet has testnet LUME tokens
-
Navigate to the browser example directory:
cd examples/browser -
Install dependencies:
pnpm install
Start the development server:
pnpm run devThis will:
- Build the application with Vite
- Start a local development server (at
http://localhost:3001by default) - Automatically open your browser
The browser example is always wired to the local SDK source.
Vite resolves @lumera-protocol/sdk-js and its browser shims to the code in ../../src, so any changes you make in sdk-js/src are immediately reflected when you run the example.
- Click the "Connect Keplr Wallet" button
- Keplr will prompt you to approve the connection
- Once connected, your address will be displayed
- The application will automatically query blockchain parameters
- Click "Choose a file to upload" to select a file from your computer
- The file name and size will be displayed
- Click "Upload to Cascade" to start the upload
- Progress will be shown with a progress bar
- When complete, a unique action ID will be assigned to your file
- After uploading, click "Download Last Uploaded File"
- The file will be downloaded from Cascade storage
- Progress will be tracked and displayed
- The file will be saved to your downloads folder
The activity log at the bottom of the page shows:
- ℹ️ Info messages (blue) - General operations
- ✓ Success messages (green) - Completed operations
⚠️ Warning messages (yellow) - Important notices- ✗ Error messages (red) - Failed operations
To create a production build:
pnpm run buildThe built files will be in the dist/ directory and can be deployed to any static hosting service.
To preview the production build locally:
pnpm run previewexamples/browser/
├── index.html # Main HTML file with UI structure
├── main.ts # TypeScript application logic
├── package.json # Dependencies and scripts
├── vite.config.ts # Vite build configuration (uses local sdk-js/src)
├── tsconfig.json # TypeScript configuration
└── README.md # This fileThe application maintains state for:
- client: LumeraClient instance
- address: Connected wallet address
- chainId: Target blockchain network
- lastActionId: Most recent upload action ID
- selectedFile: File selected for upload
- Checks for Keplr availability
- Requests wallet connection
- Creates LumeraClient with Keplr signer
- Queries blockchain parameters
- Reads selected file as ArrayBuffer
- Generates unique action ID
- Uploads to Cascade storage via SDK
- Tracks progress and displays results
- Requests file from Cascade storage
- Streams file chunks
- Combines chunks into complete file
- Triggers browser download
The application provides real-time feedback through:
- Status indicators (connected/disconnected)
- Progress bars for uploads and downloads
- Activity log with color-coded messages
- Button state management based on application state
Solution: Install the Keplr browser extension from keplr.app
Solutions:
-
Check your internet connection
-
Verify the Lumera testnet is operational
-
Try increasing timeout values in
main.ts:http: { timeout: 60000, // Increase to 60 seconds maxRetries: 5, // Increase retry attempts }
Solution: Request testnet tokens from the Lumera faucet. Your wallet needs LUME tokens to pay for transaction fees.
Troubleshooting steps:
- Check the activity log for specific error messages
- Verify your wallet is still connected
- Ensure the file size is reasonable (< 10MB for testing)
- Try with a smaller file first
- Check browser console for detailed error messages
Solutions:
- Refresh the page and try again
- Check if Keplr is locked (unlock it)
- Disable other wallet extensions that might interfere
- Clear browser cache and cookies
Source maps are enabled by default in vite.config.ts for easier debugging:
build: {
sourcemap: true,
}Vite provides automatic HMR - changes to main.ts will instantly reflect in the browser without a full page reload.
To check for TypeScript errors without building:
pnpm exec tsc --noEmitUse the browser's developer console (F12) to see detailed logs and debug issues. All log messages are duplicated to the console.
The SDK includes a Playwright-based harness that drives this example end-to-end using your existing sn-api config and Keplr profile.
Prerequisites
sn-api-serverbuilt at../sn-api-server/bin/snapi(from repo root:cd sn-api-server && API_BIN=snapi make build)- A Chrome/Chromium profile with Keplr installed and a Lumera testnet account (e.g. profile name "Matee")
~/.snapi/.envconfigured for your sn-api instance (HTTP_PORT, GRPC_ADDR, CHAIN_ID, KEY_NAME, etc.)
Environment variables
From sdk-js/ set:
export E2E_CHROME_EXECUTABLE="/usr/bin/google-chrome" # or your Chromium path
export E2E_CHROME_PROFILE_DIR="$HOME/.config/google-chrome-playwright-matee"
# Optional overrides:
# export E2E_SNAPI_BIN="$PWD/../sn-api-server/bin/snapi"
# export E2E_SNAPI_URL="http://localhost:3000"
# export E2E_BROWSER_URL="http://localhost:3001"
# Optional Keplr automation:
# export E2E_KEPLR_PASSWORD="your-keplr-password" # used to unlock the wallet
# export E2E_KEPLR_AUTO_APPROVE=1 # auto-approve Keplr popups (default)Run the harness
cd sdk-js
pnpm install
pnpm run e2e:browserThe harness will:
- Ensure sn-api is running (reusing an existing instance on
E2E_SNAPI_URLor startingsnapi serve) - Ensure this browser example dev server is running on
E2E_BROWSER_URL - Launch Chrome with your Keplr profile
- Click Connect Keplr Wallet and wait until the app shows
Connected:in the wallet info - Select a small test file (
examples/browser/test-assets/hello-lep1.txt) - Click Upload to Cascade and wait for an Upload completed log entry
- Click Download Last Uploaded File and wait for File saved to browser downloads
If E2E_KEPLR_PASSWORD is set and the selected profile has Keplr installed and enabled, the harness will attempt to unlock the wallet and auto-approve Keplr popups (connect, ADR-036 signatures, transaction, download auth). Otherwise, it will fail fast if window.keplr is not present on the test page. All other steps are fully automated, and the script fails with a non-zero exit code on timeout or error.
User clicks "Connect"
↓
Check Keplr availability
↓
Request Keplr connection (user approves)
↓
Get account address
↓
Create LumeraClient with Keplr signer
↓
Query blockchain parameters
↓
Update UI with connection statusUser selects file
↓
Read file as ArrayBuffer
↓
Convert to Uint8Array
↓
Generate unique action ID
↓
Get blockchain parameters
↓
Call client.Cascade.uploader.uploadFile()
↓
Monitor upload progress
↓
Display completion statusUser clicks "Download"
↓
Request download via action ID
↓
Get ReadableStream
↓
Read stream chunks
↓
Combine chunks into Uint8Array
↓
Create Blob from data
↓
Trigger browser download- Private Keys: Never expose mnemonics or private keys in browser code
- Signature Requests: Always verify what you're signing in Keplr prompts
- HTTPS: Use HTTPS in production to protect wallet communications
- CSP Headers: Implement Content Security Policy headers for production
- Explore the Node.js Examples for CLI workflows
- Read the SDK Documentation for API reference
- Check the test suite for more usage patterns
- Try uploading different file types and sizes
For issues or questions:
- GitHub Issues: https://github.com/LumeraProtocol/sdk-js/issues
- Documentation: https://docs.lumera.io
- Discord: https://discord.gg/lumera