ā” Quickstart Tutorial
A complete BRDZ SDK application with authentication, wallet management, and basic transactions. Perfect for understanding core concepts and getting started quickly.
Prerequisitesā
- Node.js 16+ installed
- Basic JavaScript/TypeScript knowledge
- API Key configured
- Code editor (VS Code recommended)
Step 1: Project Setupā
Create New Projectā
# Create project directory
mkdir my-brdz-app
cd my-brdz-app
# Initialize Node.js project
npm init -y
# Install BRDZ SDK
npm install anantla_sdk
# Install additional dependencies
npm install dotenv
Environment Configurationā
Create .env file:
# BRDZ SDK Configuration
BRDZ_API_BASE=https://api.brdz.link/api
BRDZ_API_KEY=your_api_key_here
# Replace with your actual API key from setup guide
Basic Project Structureā
my-brdz-app/
āāā src/
ā āāā index.js
ā āāā auth.js
ā āāā wallet.js
ā āāā utils.js
āāā .env
āāā package.json
āāā README.md
Step 2: SDK Initializationā
Create src/utils.js:
// src/utils.js
require('dotenv').config();
const brdzSDK = require('anantla_sdk');
class BRDZManager {
constructor() {
this.initialized = false;
this.currentUser = null;
}
async init() {
try {
console.log('š Initializing BRDZ SDK...');
// Configure SDK
const config = brdzSDK.config;
config.setBaseUrl(process.env.BRDZ_API_BASE);
config.setApiKey(process.env.BRDZ_API_KEY);
// Check if user token exists (for returning users)
if (process.env.BRDZ_USER_TOKEN) {
config.setToken(process.env.BRDZ_USER_TOKEN);
}
// Validate setup
const utils = brdzSDK.utils;
const isValid = utils.validateSDKSetup();
if (isValid) {
this.initialized = true;
console.log('ā
BRDZ SDK initialized successfully');
} else {
throw new Error('SDK validation failed');
}
} catch (error) {
console.error('ā SDK initialization failed:', error.message);
throw error;
}
}
isReady() {
return this.initialized;
}
setCurrentUser(user) {
this.currentUser = user;
}
getCurrentUser() {
return this.currentUser;
}
}
module.exports = { BRDZManager, brdzSDK };
Step 3: Authentication Implementationā
Create src/auth.js:
// src/auth.js
const { brdzSDK } = require('./utils');
class AuthManager {
constructor(brdzManager) {
this.brdz = brdzManager;
this.auth = brdzSDK.auth;
this.twofa = brdzSDK.twofa;
}
async register(userData) {
if (!this.brdz.isReady()) {
throw new Error('BRDZ SDK not initialized');
}
try {
console.log('š Registering new user...');
const result = await this.auth.registerUser(userData);
console.log('ā
Registration successful:', result.user?.username);
return result;
} catch (error) {
console.error('ā Registration failed:', error.message);
throw error;
}
}
async login(email, password) {
try {
console.log('š Logging in user...');
const result = await this.auth.loginUser(email, password);
if (result.requires_2fa) {
console.log('š 2FA required for this account');
return {
success: false,
requires_2fa: true,
user_id: result.user_id
};
}
// Save token and update SDK config
const config = brdzSDK.config;
config.setToken(result.token);
this.brdz.setCurrentUser(result.user);
console.log('ā
Login successful:', result.user?.username);
return result;
} catch (error) {
console.error('ā Login failed:', error.message);
throw error;
}
}
async loginWith2FA(userId, code) {
try {
console.log('š Completing 2FA login...');
const result = await this.auth.completeLoginWith2FA(userId, code);
// Save token and update SDK config
const config = brdzSDK.config;
config.setToken(result.token);
this.brdz.setCurrentUser(result.user);
console.log('ā
2FA login successful');
return result;
} catch (error) {
console.error('ā 2FA login failed:', error.message);
throw error;
}
}
async getUserProfile(userId) {
try {
const profile = await this.auth.getUserProfile(userId);
console.log('š¤ User profile retrieved:', profile.username);
return profile;
} catch (error) {
console.error('ā Failed to get profile:', error.message);
throw error;
}
}
}
module.exports = { AuthManager };
Step 4: Wallet Managementā
Create src/wallet.js:
// src/wallet.js
const { brdzSDK } = require('./utils');
class WalletManager {
constructor(brdzManager) {
this.brdz = brdzManager;
this.cryptoWallet = brdzSDK.cryptoWallet;
this.onchain = brdzSDK.onchain;
}
async createWallet(walletName, userId) {
try {
console.log('š¼ Creating new wallet...');
const wallet = await this.cryptoWallet.createWallet({
wallet_name: walletName,
user_id: userId
});
console.log('ā
Wallet created:', wallet.wallet_name);
return wallet;
} catch (error) {
console.error('ā Wallet creation failed:', error.message);
throw error;
}
}
async getUserWallets(userId) {
try {
console.log('š Getting user wallets...');
const wallets = await this.cryptoWallet.getUserWallets(userId);
console.log(`ā
Found ${wallets.length} wallets`);
return wallets;
} catch (error) {
console.error('ā Failed to get wallets:', error.message);
throw error;
}
}
async addChainToWallet(walletId, chainId) {
try {
console.log(`āļø Adding ${chainId} chain to wallet...`);
const result = await this.cryptoWallet.addChainAddress(walletId, {
chain_id: chainId
});
console.log('ā
Chain added successfully');
return result;
} catch (error) {
console.error('ā Failed to add chain:', error.message);
throw error;
}
}
async getWalletBalance(walletId, chainId) {
try {
console.log('š° Checking wallet balance...');
const balance = await this.cryptoWallet.balance.getChain(walletId, chainId);
console.log(`ā
Balance retrieved for ${chainId}`);
return balance;
} catch (error) {
console.error('ā Failed to get balance:', error.message);
throw error;
}
}
async getTransactionHistory(userId) {
try {
console.log('š Getting transaction history...');
const history = await this.onchain.getTransactionHistory(userId, {
limit: 10
});
console.log(`ā
Retrieved ${history.data?.length || 0} transactions`);
return history;
} catch (error) {
console.error('ā Failed to get transaction history:', error.message);
throw error;
}
}
// AI-powered wallet operations
async aiWalletOperation(userInput, userId) {
try {
console.log('š¤ Processing AI wallet request...');
const result = await this.cryptoWallet.processAIIntent({
user_input: userInput,
user_id: userId
});
console.log('ā
AI operation completed');
return result;
} catch (error) {
console.error('ā AI operation failed:', error.message);
throw error;
}
}
}
module.exports = { WalletManager };
Step 5: Main Applicationā
Create src/index.js:
// src/index.js
const { BRDZManager } = require('./utils');
const { AuthManager } = require('./auth');
const { WalletManager } = require('./wallet');
class MyBRDZApp {
constructor() {
this.brdz = new BRDZManager();
this.auth = null;
this.wallet = null;
this.currentUser = null;
}
async initialize() {
try {
console.log('š Starting BRDZ Application...');
// Initialize SDK
await this.brdz.init();
// Initialize managers
this.auth = new AuthManager(this.brdz);
this.wallet = new WalletManager(this.brdz);
console.log('ā
Application initialized successfully\n');
} catch (error) {
console.error('ā Application initialization failed:', error.message);
process.exit(1);
}
}
async runDemo() {
try {
console.log('='.repeat(50));
console.log('šÆ BRDZ SDK Demo Application');
console.log('='.repeat(50));
// Demo 1: User Registration
console.log('\nš Demo 1: User Registration');
const userData = {
email: 'demo@example.com',
username: 'demouser',
client_alias: 'Demo App',
client_type: 'individual',
country_code: 'ID',
phone: '+628123456789'
};
try {
const registerResult = await this.auth.register(userData);
console.log('Registration demo completed');
} catch (error) {
if (error.message.includes('already exists')) {
console.log('User already exists, continuing with login demo...');
} else {
throw error;
}
}
// Demo 2: User Login
console.log('\nš Demo 2: User Login');
try {
const loginResult = await this.auth.login('demo@example.com', 'password123');
if (loginResult.requires_2fa) {
console.log('š This account has 2FA enabled');
console.log('In production, you would prompt user for 2FA code here');
} else {
this.currentUser = loginResult.user;
console.log('Login demo completed');
}
} catch (error) {
console.log('Login demo failed (expected if demo user not found)');
}
// Demo 3: Wallet Operations (requires authentication)
if (this.currentUser) {
console.log('\nš¼ Demo 3: Wallet Operations');
// Create wallet
const wallet = await this.wallet.createWallet('Demo Wallet', this.currentUser.id);
console.log('Wallet created:', wallet.wallet_name);
// Get user wallets
const wallets = await this.wallet.getUserWallets(this.currentUser.id);
console.log('User wallets retrieved:', wallets.length);
// Add chain support
if (wallets.length > 0) {
const walletId = wallets[0].bw_id;
await this.wallet.addChainToWallet(walletId, 'sepolia');
}
// AI Wallet Demo
console.log('\nš¤ Demo 4: AI Wallet Operations');
const aiResult = await this.wallet.aiWalletOperation(
'Show me my wallet balances',
this.currentUser.id
);
console.log('AI Response:', aiResult.agent_response?.message);
} else {
console.log('\nāļø Skipping wallet demos (authentication required)');
}
console.log('\nš Demo completed successfully!');
console.log('Next steps: Explore more SDK modules and build your own features');
} catch (error) {
console.error('ā Demo failed:', error.message);
}
}
async run() {
await this.initialize();
await this.runDemo();
}
}
// Run the application
const app = new MyBRDZApp();
app.run().catch(console.error);
Step 6: Test Your Applicationā
Run the Demoā
# Make sure you have your API key in .env file
node src/index.js
Expected Outputā
š Starting BRDZ Application...
š Initializing BRDZ SDK...
ā
BRDZ SDK initialized successfully
ā
Application initialized successfully
==================================================
šÆ BRDZ SDK Demo Application
==================================================
š Demo 1: User Registration
ā
Registration successful: demouser
š Demo 2: User Login
ā
Login successful: demouser
š¼ Demo 3: Wallet Operations
š¼ Creating new wallet...
ā
Wallet created: Demo Wallet
š Getting user wallets...
ā
Found 1 wallets
āļø Adding sepolia chain to wallet...
ā
Chain added successfully
š¤ Demo 4: AI Wallet Operations
š¤ Processing AI wallet request...
ā
AI operation completed
AI Response: I can see your wallet information. You currently have 1 wallet...
š Demo completed successfully!
Next steps: Explore more SDK modules and build your own features
Step 7: Explore More Featuresā
Add Package Scriptsā
Update your package.json:
{
"name": "my-brdz-app",
"version": "1.0.0",
"scripts": {
"start": "node src/index.js",
"demo": "node src/index.js",
"test": "echo \"Run: npm run demo\""
},
"dependencies": {
"anantla_sdk": "latest",
"dotenv": "latest"
}
}
Try Additional Modulesā
// Add to your app for more features
// AI Commerce (MCP)
const mcp = brdzSDK.mcp;
const productIntent = await mcp.step1_detectIntent({
prompt: "I want to buy headphones from tokopedia"
});
// Cross-chain Operations
const crosschain = brdzSDK.crosschain;
const balance = await crosschain.getUSDCBalance('sepolia', 'your_wallet_address');
// Traditional Wallet
const wallet = brdzSDK.wallet;
const walletBalance = await wallet.getBalance();
// Foreign Exchange
const fx = brdzSDK.fx;
const rate = await fx.getRate('USD', 'IDR');
Common Issues & Solutionsā
Issue: API Key Missingā
Error: API Key required. Call config.setApiKey() first
Solution: Make sure your .env file has BRDZ_API_KEY set correctly
Issue: Authentication Requiredā
Error: Authentication required. Call auth.loginUser() first
Solution: Login with valid user credentials before accessing authenticated endpoints
Issue: Module Not Foundā
Error: Cannot find module 'anantla_sdk'
Solution: Install the SDK: npm install anantla_sdk
What You've Learnedā
ā
SDK Initialization: How to configure and initialize BRDZ SDK
ā
Authentication: User registration, login, and 2FA handling
ā
Wallet Management: Create wallets, add chains, check balances
ā
AI Integration: Use AI-powered wallet operations
ā
Error Handling: Proper error handling and validation
ā
Project Structure: Organized, maintainable code architecture
Next Stepsā
Now that you have a working BRDZ application:
- ā API Key Setup - Complete
- ā Authentication - Complete
- ā Quickstart Tutorial - Complete
- React Integration - Build frontend components
Explore More Modulesā
- Crypto Wallet (ABSK) - Advanced wallet features
- AI Commerce (MCP) - AI-powered shopping
- Cross-chain - Multi-blockchain operations
- Two-Factor Auth - Enhanced security
If you encounter issues:
- Email: contact@anantla.com
- Contact: BRDZ Contact Form