Skip to main content

⚔ Quickstart Tutorial

What You'll Build

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:

.env
# 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:

  1. āœ… API Key Setup - Complete
  2. āœ… Authentication - Complete
  3. āœ… Quickstart Tutorial - Complete
  4. React Integration - Build frontend components

Explore More Modules​


Need Help?

If you encounter issues: