Observed since 21 Oct, 08:55 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
TypeScript SDK for integrating with Octra Wallet Extension
A comprehensive TypeScript/JavaScript SDK that enables seamless integration between decentralized applications (DApps) and the Octra Wallet browser extension. This toolkit provides developers with a secure, type-safe, and user-friendly way to interact with the Octra blockchain network.
The Octra Wallet SDK bridges the gap between web applications and blockchain functionality, allowing developers to:
Disclaimer: This is an unofficial, community-built project for the Octra network. It is not affiliated with, endorsed by, or maintained by the official Octra team.
Note: This SDK is developed by NullxGery (0xGery) for the Octra network ecosystem.
Major Performance & Reliability Improvements:
# npm
npm install @0xgery/wallet-sdk
# yarn
yarn add @0xgery/wallet-sdk
# CDN (for quick testing)
<script src="https://unpkg.com/@0xgery/wallet-sdk@0.2.0/dist/index.umd.js"></script>
import { OctraWallet } from '@0xgery/wallet-sdk';
// Create wallet instance
const wallet = new OctraWallet({
appName: 'My Awesome DApp',
appDescription: 'A revolutionary decentralized application',
requiredPermissions: ['read_balance', 'send_transactions']
});
// Initialize and connect
await wallet.initialize();
const connection = await wallet.connect();
console.log('Connected!', connection.address);
// Get balance
const balance = await wallet.getBalance();
console.log('Balance:', balance.total, 'OCT');
// Send transaction
const result = await wallet.sendTransaction({
to: 'recipient_address',
amount: 10.5,
message: 'Hello from my DApp!'
});
console.log('Transaction sent:', result.txHash);
import { createOctraWallet } from '@0xgery/wallet-sdk';
const wallet = await createOctraWallet({
appName: 'My DApp',
autoConnect: true,
debug: true
});
if (wallet.isConnected()) {
const balance = await wallet.getBalance();
console.log('Balance:', balance.total, 'OCT');
}
new OctraWallet(config: SDKConfig)
SDKConfig:
interface SDKConfig {
appName: string; // Required: Your DApp name
appDescription?: string; // App description for user
appVersion?: string; // App version (default: '1.0.0')
appUrl?: string; // App URL (auto-detected)
appIcon?: string; // App icon URL
requiredPermissions?: Permission[]; // Required permissions
networkId?: string; // Target network ('mainnet', 'testnet')
debug?: boolean; // Enable debug logging
}
await wallet.initialize(): Promise<boolean>
Initialize the SDK. Must be called before any other methods.
await wallet.connect(options?: ConnectOptions): Promise<ConnectEvent>
await wallet.disconnect(): Promise<void>
wallet.isConnected(): boolean
wallet.getConnectionInfo(): ConnectionInfo
wallet.getAddress(): string | null
await wallet.getBalance(forceRefresh?: boolean): Promise<Balance>
await wallet.getNetworkInfo(): Promise<NetworkInfo>
await wallet.sendTransaction(txData: TransactionData): Promise<TransactionResult>
await wallet.getTransactionHistory(page?: number, limit?: number): Promise<TransactionHistory>
await wallet.getPrivateBalanceInfo(): Promise<PrivateBalanceInfo>
await wallet.encryptBalance(amount: number): Promise<boolean>
await wallet.decryptBalance(amount: number): Promise<boolean>
await wallet.sendPrivateTransfer(data: PrivateTransferData): Promise<TransactionResult>
await wallet.getPendingPrivateTransfers(): Promise<PendingPrivateTransfer[]>
await wallet.claimPrivateTransfer(transferId: string): Promise<TransactionResult>
wallet.on(event: WalletEventType, listener: (data) => void): void
wallet.off(event: WalletEventType, listener: Function): void
wallet.once(event: WalletEventType, listener: (data) => void): void
Events:
connect - Wallet connecteddisconnect - Wallet disconnectedaccountChanged - Account switchedbalanceChanged - Balance updatednetworkChanged - Network switchedtransactionConfirmed - Transaction confirmederror - Error occurredextensionLocked - Extension was lockedextensionUnlocked - Extension was unlockedThe SDK now exports useful utility functions:
import {
// Validation utilities
isValidAddress,
isValidAmount,
isValidMessage,
isValidFeeLevel,
isValidNetworkId,
// Formatting utilities
formatOCT,
formatAddress,
formatTimestamp,
formatTxHash,
// Conversion utilities
toMicroOCT,
fromMicroOCT,
// Error utilities
createErrorMessage,
isErrorType,
// Async utilities
delay,
retry,
withTimeout,
// Browser utilities
isBrowser,
checkBrowserSupport,
// Development utilities
generateMockData,
createLogger
} from '@0xgery/wallet-sdk';
// Example usage
const isValid = isValidAddress('OCTxyz123...');
const formatted = formatOCT(123.456789, 2); // "123.46"
const shortAddr = formatAddress('OCTxyz123...abc', 6, 4); // "OCTxyz...abc"
The SDK includes advanced debugging tools available in development environments:
// Available at window.__OCTRA_SDK_UTILS__ in development
window.__OCTRA_SDK_UTILS__.enableDebugMode(); // Enable detailed logging
window.__OCTRA_SDK_UTILS__.disableDebugMode(); // Disable logging
window.__OCTRA_SDK_UTILS__.getSDKInfo(); // Get SDK version info
window.__OCTRA_SDK_UTILS__.simulateExtensionEvent('balanceChanged', data); // Test events
window.__OCTRA_SDK_UTILS__.showWelcome(); // Show SDK welcome message
Automatic Development Detection:
import React, { useState, useEffect } from 'react';
import { OctraWallet, createOctraWallet } from '@0xgery/wallet-sdk';
function WalletConnector() {
const [wallet, setWallet] = useState(null);
const [connected, setConnected] = useState(false);
const [address, setAddress] = useState('');
const [balance, setBalance] = useState(0);
useEffect(() => {
async function initWallet() {
try {
const walletInstance = await createOctraWallet({
appName: 'My React DApp',
debug: process.env.NODE_ENV === 'development'
});
// Setup event listeners
walletInstance.on('connect', (event) => {
setConnected(true);
setAddress(event.address);
setBalance(event.balance.total);
});
walletInstance.on('disconnect', () => {
setConnected(false);
setAddress('');
setBalance(0);
});
walletInstance.on('balanceChanged', (event) => {
setBalance(event.newBalance.total);
});
setWallet(walletInstance);
} catch (error) {
console.error('Failed to initialize wallet:', error);
}
}
initWallet();
}, []);
const connect = async () => {
try {
await wallet.connect();
} catch (error) {
alert('Connection failed: ' + error.message);
}
};
const sendTransaction = async () => {
try {
const result = await wallet.sendTransaction({
to: 'recipient_address',
amount: 1,
message: 'Test from React DApp'
});
alert('Transaction sent: ' + result.txHash);
} catch (error) {
alert('Transaction failed: ' + error.message);
}
};
return (
<div>
<h2>Octra Wallet Integration</h2>
{!connected ? (
<button onClick={connect} disabled={!wallet}>
{wallet ? 'Connect Wallet' : 'Loading...'}
</button>
) : (
<div>
<p>Connected: {address}</p>
<p>Balance: {balance} OCT</p>
<button onClick={() => wallet.disconnect()}>Disconnect</button>
<button onClick={sendTransaction}>Send Test Transaction</button>
</div>
)}
</div>
);
}
export default WalletConnector;
<template>
<div>
<h2>Octra Wallet Integration</h2>
<div v-if="!connected">
<button @click="connect" :disabled="!wallet">
{{ wallet ? 'Connect Wallet' : 'Loading...' }}
</button>
</div>
<div v-else>
<p>Connected: {{ address }}</p>
<p>Balance: {{ balance }} OCT</p>
<button @click="disconnect">Disconnect</button>
<button @click="sendTransaction">Send Test Transaction</button>
</div>
</div>
</template>
<script>
import { createOctraWallet } from '@0xgery/wallet-sdk';
export default {
data() {
return {
wallet: null,
connected: false,
address: '',
balance: 0
};
},
async mounted() {
try {
this.wallet = await createOctraWallet({
appName: 'My Vue DApp',
debug: process.env.NODE_ENV === 'development'
});
// Setup event listeners
this.wallet.on('connect', (event) => {
this.connected = true;
this.address = event.address;
this.balance = event.balance.total;
});
this.wallet.on('disconnect', () => {
this.connected = false;
this.address = '';
this.balance = 0;
});
} catch (error) {
console.error('Failed to initialize wallet:', error);
}
},
methods: {
async connect() {
try {
await this.wallet.connect();
} catch (error) {
alert('Connection failed: ' + error.message);
}
},
async disconnect() {
await this.wallet.disconnect();
},
async sendTransaction() {
try {
const result = await this.wallet.sendTransaction({
to: 'recipient_address',
amount: 1,
message: 'Test from Vue DApp'
});
alert('Transaction sent: ' + result.txHash);
} catch (error) {
alert('Transaction failed: ' + error.message);
}
}
}
};
</script>
<!DOCTYPE html>
<html>
<head>
<title>Octra Wallet Integration</title>
<script src="https://unpkg.com/@0xgery/wallet-sdk/dist/index.umd.js"></script>
</head>
<body>
<div id="app">
<h2>Octra Wallet Integration</h2>
<div id="connection-status">Loading...</div>
<button id="connect-btn" style="display: none;">Connect Wallet</button>
<button id="disconnect-btn" style="display: none;">Disconnect</button>
<button id="send-btn" style="display: none;">Send Transaction</button>
</div>
<script>
let wallet;
async function initWallet() {
try {
wallet = await OctraWalletSDK.createOctraWallet({
appName: 'My Vanilla JS DApp',
debug: true
});
// Setup event listeners
wallet.on('connect', (event) => {
document.getElementById('connection-status').textContent =
`Connected: ${event.address} (${event.balance.total} OCT)`;
document.getElementById('connect-btn').style.display = 'none';
document.getElementById('disconnect-btn').style.display = 'inline';
document.getElementById('send-btn').style.display = 'inline';
});
wallet.on('disconnect', () => {
document.getElementById('connection-status').textContent = 'Disconnected';
document.getElementById('connect-btn').style.display = 'inline';
document.getElementById('disconnect-btn').style.display = 'none';
document.getElementById('send-btn').style.display = 'none';
});
// Show connect button
document.getElementById('connection-status').textContent = 'Ready to connect';
document.getElementById('connect-btn').style.display = 'inline';
} catch (error) {
document.getElementById('connection-status').textContent = 'Error: ' + error.message;
console.error('Failed to initialize wallet:', error);
}
}
// Event handlers
document.getElementById('connect-btn').addEventListener('click', async () => {
try {
await wallet.connect();
} catch (error) {
alert('Connection failed: ' + error.message);
}
});
document.getElementById('disconnect-btn').addEventListener('click', async () => {
await wallet.disconnect();
});
document.getElementById('send-btn').addEventListener('click', async () => {
try {
const result = await wallet.sendTransaction({
to: 'recipient_address',
amount: 1,
message: 'Test from Vanilla JS DApp'
});
alert('Transaction sent: ' + result.txHash);
} catch (error) {
alert('Transaction failed: ' + error.message);
}
});
// Initialize on page load
initWallet();
</script>
</body>
</html>
import { isValidAddress, isValidAmount } from '@0xgery/wallet-sdk';
// Always validate user inputs
const recipientAddress = userInput.trim();
if (!isValidAddress(recipientAddress)) {
throw new Error('Invalid recipient address');
}
const amount = parseFloat(userAmountInput);
if (!isValidAmount(amount)) {
throw new Error('Invalid transaction amount');
}
import { OctraWalletError, ErrorCode, isErrorType } from '@0xgery/wallet-sdk';
try {
await wallet.sendTransaction(txData);
} catch (error) {
if (isErrorType(error, ErrorCode.INSUFFICIENT_BALANCE)) {
alert('Not enough balance for this transaction');
} else if (isErrorType(error, ErrorCode.USER_REJECTED)) {
console.log('User cancelled the transaction');
} else if (isErrorType(error, ErrorCode.EXTENSION_NOT_FOUND)) {
// Enhanced diagnostics available
console.error('Extension not found. Details:', error.details);
alert('Please install Octra Wallet extension');
} else {
// All errors now include detailed context
console.error('Transaction failed:', {
message: error.message,
code: error.code,
details: error.details // Browser/extension state info
});
alert('Transaction failed: ' + error.message);
}
}
const networkInfo = await wallet.getNetworkInfo();
if (networkInfo.id !== 'mainnet') {
console.warn('Not connected to mainnet!');
// Show warning to user or switch network
}
git clone https://github.com/0xGery/Octra.git
cd Octra/wallet-sdk
npm install
npm run build
npm run test
npm run typecheck
npm run lint
The SDK is fully typed with TypeScript. Import types as needed:
import {
Balance,
TransactionData,
TransactionResult,
WalletEventType,
ConnectEvent,
ErrorCode
} from '@0xgery/wallet-sdk';
| Code | Description |
|---|---|
EXTENSION_NOT_FOUND | Octra Wallet extension not installed |
CONNECTION_REFUSED | User denied connection request |
USER_REJECTED | User rejected transaction/action |
INSUFFICIENT_BALANCE | Not enough balance for transaction |
INVALID_ADDRESS | Invalid wallet address format |
INVALID_AMOUNT | Invalid transaction amount |
NETWORK_ERROR | Network communication failure |
TRANSACTION_FAILED | Transaction processing failed |
PERMISSION_DENIED | Missing required permissions |
WALLET_LOCKED | Wallet needs to be unlocked |
MIT License - see LICENSE for details.
Built by NullxGery (0xGery) for the Octra network
Download counts and popularity will appear here as the collector receives them.
This describes our collected data; it is not a security assessment.
Observed since 21 Oct, 08:55 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:b1c1479b6592579d18387873cfb55fe7afa08d6a9275b47ffa61cf7f825c6324