@gorbchain-xyz/chaindecode
Version:
GorbchainSDK V1.3+ - Complete Solana development toolkit with advanced cryptography, messaging, and collaboration features. Build secure applications with blockchain, DeFi, and end-to-end encryption.
1,210 lines (995 loc) • 33.4 kB
Markdown
# GorbchainSDK V1.3+ - The Complete Solana Development Toolkit 🚀
**Build production-ready Solana applications with blockchain, DeFi, and cryptography in minutes, not months**
[](https://badge.fury.io/js/@gorbchain-xyz%2Fchaindecode)
[](https://www.typescriptlang.org/)
[](https://opensource.org/licenses/MIT)
[](https://www.npmjs.com/package/@gorbchain-xyz/chaindecode)
## Why GorbchainSDK V1.3+?
While Solana's Web3.js provides raw RPC access, **GorbchainSDK V1.3+** delivers a complete ecosystem:
### 🔐 **NEW: Advanced Cryptography Suite**
- **Personal Encryption** - Private key-based encryption/decryption
- **Direct Encryption** - Public key encryption between parties
- **Group Encryption** - Multi-recipient encryption with role-based access
- **Signature Groups** - Dynamic membership with signature-based access control
- **Shared Keys** - Managed encryption keys with granular permissions
- **Scalable Contexts** - Auto-scaling from 1-to-N recipient encryption
### 🎯 **Enhanced Blockchain Analysis**
- **Rich Transaction Analysis** - Decode ANY Solana transaction with human-readable insights
- **Real-time RPC Monitoring** - Advanced connection management and health checks
- **Cross-program Correlation** - Understand complex multi-instruction transactions
### 🚀 **DeFi & Token Operations**
- **One-Line Token Creation** - Launch tokens with metadata in seconds using Token22
- **NFT Minting Made Simple** - Create Metaplex Core NFTs with royalties and attributes
- **Portfolio Intelligence** - Track wallets, analyze holdings, monitor performance
- **⚡ 10x Faster Development** - Pre-built integrations for DeFi, NFTs, and analytics
### 🔧 **Developer Experience**
- **Framework Ready** - Works seamlessly with React, Vue, Next.js, and Node.js
- **Interactive Playground** - Test all features with built-in crypto playground
- **TypeScript First** - Full type safety and IntelliSense support
## 🚀 Installation
```bash
npm install @gorbchain-xyz/chaindecode
# or
yarn add @gorbchain-xyz/chaindecode
# or
pnpm add @gorbchain-xyz/chaindecode
```
## 📋 Table of Contents
- [🔐 Cryptography Suite](#-cryptography-suite)
- [Personal Encryption](#personal-encryption)
- [Direct Encryption](#direct-encryption)
- [Group & Signature-Based Encryption](#group--signature-based-encryption)
- [Shared Key Management](#shared-key-management)
- [Scalable Encryption Contexts](#scalable-encryption-contexts)
- [🎯 Transaction Analysis](#-transaction-analysis)
- [🚀 Token & NFT Operations](#-token--nft-operations)
- [🌐 RPC & Network Management](#-rpc--network-management)
- [📊 Portfolio Intelligence](#-portfolio-intelligence)
- [🎮 Interactive Playground](#-interactive-playground)
- [🏗️ Framework Integration](#️-framework-integration)
- [📚 Complete API Reference](#-complete-api-reference)
## 🔐 Cryptography Suite
GorbchainSDK V1.3+ introduces a comprehensive cryptography suite for secure data handling, key management, and encrypted communications on Solana.
### Personal Encryption
Encrypt data with your private key - only you can decrypt:
```typescript
import { encryptPersonal, decryptPersonalString } from '@gorbchain-xyz/chaindecode';
// Encrypt sensitive data
const encrypted = await encryptPersonal(
'My secret message',
privateKey,
{ compress: true }
);
// Decrypt your data
const decrypted = await decryptPersonalString(encrypted, privateKey);
console.log(decrypted); // "My secret message"
```
### Direct Encryption
Encrypt data for a specific recipient using their public key:
```typescript
import { encryptDirect, decryptDirectString } from '@gorbchain-xyz/chaindecode';
// Alice encrypts for Bob
const encrypted = await encryptDirect(
'Hello Bob!',
bobPublicKey,
alicePrivateKey,
{ compress: true }
);
// Bob decrypts Alice's message
const decrypted = await decryptDirectString(encrypted, bobPrivateKey);
console.log(decrypted); // "Hello Bob!"
```
### Group & Signature-Based Encryption
Create dynamic groups with role-based permissions and signature-based access control:
```typescript
import {
createSignatureGroup,
encryptForSignatureGroup,
addMemberToSignatureGroup,
MemberRole
} from '@gorbchain-xyz/chaindecode';
// Create a signature-based group
const group = await createSignatureGroup(
'Project Alpha Team',
creatorPrivateKey,
[
{ publicKey: bobPublicKey, role: MemberRole.ADMIN },
{ publicKey: charliePublicKey, role: MemberRole.MEMBER }
],
{
allowDynamicMembership: true,
maxMembers: 20,
requireSignatureVerification: true
}
);
// Encrypt for all group members
const encrypted = await encryptForSignatureGroup(
'Team announcement: New feature launch!',
group,
senderPrivateKey,
senderPublicKey
);
// Add new members dynamically
const updatedGroup = await addMemberToSignatureGroup(
group,
{ publicKey: dianaPublicKey, role: MemberRole.VIEWER },
adminPrivateKey,
adminPublicKey
);
```
### Shared Key Management
Manage shared encryption keys with granular permissions:
```typescript
import { SharedKeyManager } from '@gorbchain-xyz/chaindecode';
const sharedKeyManager = new SharedKeyManager();
// Create shared key with specific permissions
const sharedKey = await sharedKeyManager.createSharedKey(
{
name: 'Team Documents Key',
purpose: 'Secure document sharing',
creator: creatorPublicKey
},
[
{
publicKey: alicePublicKey,
permissions: { canDecrypt: true, canEncrypt: true, canShare: true, canRevoke: true }
},
{
publicKey: bobPublicKey,
permissions: { canDecrypt: true, canEncrypt: true, canShare: false, canRevoke: false }
}
],
creatorPrivateKey
);
// Encrypt with shared key
const encrypted = await sharedKeyManager.encryptWithSharedKey(
'Confidential team document',
sharedKey.keyId,
senderPrivateKey,
senderPublicKey
);
// Add recipients to existing shared key
const updatedKey = await sharedKeyManager.addRecipientsToSharedKey(
sharedKey.keyId,
[{
publicKey: charliePublicKey,
permissions: { canDecrypt: true, canEncrypt: false, canShare: false, canRevoke: false }
}],
authorizerPrivateKey,
authorizerPublicKey
);
```
### Scalable Encryption Contexts
Auto-scaling encryption that transitions from direct to group encryption based on recipient count:
```typescript
import { ScalableEncryptionManager } from '@gorbchain-xyz/chaindecode';
const manager = new ScalableEncryptionManager();
// Create context that starts with direct encryption
const { context } = await manager.createEncryptionContext(
'Project Communications',
'Team messaging that scales',
initialRecipientPublicKey,
creatorPrivateKey,
{ autoTransitionThreshold: 3 }
);
// Encrypt data (uses direct encryption for 1-2 recipients)
const encrypted1 = await manager.encryptInContext(
context.contextId,
'Hello team member!',
senderPrivateKey
);
// Add more recipients (automatically transitions to shared key when threshold reached)
const updatedContext = await manager.addRecipientsToContext(
context.contextId,
[charliePublicKey, dianaPublicKey, evePublicKey],
authorizerPrivateKey,
authorizerPublicKey
);
// Now uses shared key encryption automatically
const encrypted2 = await manager.encryptInContext(
context.contextId,
'Hello everyone! This uses shared key now.',
senderPrivateKey
);
```
## 🌐 RPC & Network Management
GorbchainSDK provides advanced RPC connection management with health monitoring, automatic retries, and connection pooling.
### Basic RPC Configuration
```typescript
import { GorbchainSDK } from '@gorbchain-xyz/chaindecode';
const sdk = new GorbchainSDK({
rpcEndpoint: 'https://api.mainnet-beta.solana.com',
network: 'mainnet',
timeout: 30000, // 30 seconds
retries: 3, // Retry failed requests
retryDelay: 1000, // Wait 1s between retries
});
```
### Advanced RPC Configuration
```typescript
const sdk = new GorbchainSDK({
rpcEndpoint: 'https://api.mainnet-beta.solana.com',
network: 'mainnet',
// Connection pooling for high-throughput applications
connectionPool: {
size: 10,
minConnections: 2,
maxConnections: 20,
idleTimeoutMs: 30000
},
// Advanced retry configuration
retryConfig: {
retries: 5,
retryDelay: 1000,
exponentialBackoff: true,
maxRetryDelay: 10000,
retryCondition: (error) => error.code !== 'INVALID_SIGNATURE'
},
// Health monitoring
healthCheck: {
enabled: true,
interval: 30000, // Check every 30 seconds
timeout: 5000, // Health check timeout
onHealthChange: (isHealthy) => {
console.log(`RPC Health: ${isHealthy ? 'OK' : 'DEGRADED'}`);
}
},
// Request caching
cache: {
enabled: true,
ttl: 60000, // Cache for 1 minute
maxSize: 1000 // Max cached items
}
});
```
### Network Health Monitoring
```typescript
// Check RPC health
const health = await sdk.getNetworkHealth();
console.log(`RPC Status: ${health.status}`);
console.log(`Latency: ${health.latency}ms`);
console.log(`Block Height: ${health.blockHeight}`);
console.log(`TPS: ${health.transactionsPerSecond}`);
// Monitor network status
sdk.onNetworkStatusChange((status) => {
if (status.isHealthy) {
console.log('Network is healthy');
} else {
console.log(`Network issues detected: ${status.issues.join(', ')}`);
}
});
```
### RPC Endpoint Recommendations
| Network | Recommended Endpoints | Performance | Rate Limits |
|---------|---------------------|-------------|-------------|
| **Mainnet** | `https://api.mainnet-beta.solana.com` | Standard | 100 req/s |
| **Mainnet Premium** | `https://solana-api.projectserum.com` | High | 1000 req/s |
| **Devnet** | `https://api.devnet.solana.com` | Standard | Unlimited |
| **Testnet** | `https://api.testnet.solana.com` | Standard | Unlimited |
| **Custom RPC** | Your Helius/QuickNode endpoint | Premium | Custom |
## 🎮 Interactive Playground
Test all SDK features with the built-in interactive playground:
```bash
# Clone the repository
git clone https://github.com/gorbchain/sdk.git
cd sdk/examples/react-docs
# Install dependencies
npm install
# Start the playground
npm start
```
Visit `http://localhost:3000/crypto-playground` to:
- ✅ Generate test keypairs
- ✅ Test all encryption methods
- ✅ Experiment with group management
- ✅ Try scalable encryption contexts
- ✅ Debug with real-time results
### Playground Features
The crypto playground provides:
1. **Key Generation**: Generate Solana keypairs for testing
2. **Personal Encryption**: Test private key-based encryption
3. **Direct Encryption**: Test public key encryption between parties
4. **Signature Groups**: Create and manage dynamic groups
5. **Scalable Contexts**: Test auto-scaling encryption
6. **Shared Keys**: Manage shared encryption keys
7. **Digital Signatures**: Sign and verify data
## 💡 Quick Examples
### 1. Decode Any Transaction (The Killer Feature)
```typescript
import { GorbchainSDK } from '@gorbchain-xyz/chaindecode';
const sdk = new GorbchainSDK({
rpcEndpoint: 'https://api.mainnet-beta.solana.com',
network: 'mainnet'
});
// Decode a Raydium swap, Jupiter trade, or ANY transaction
const decoded = await sdk.getAndDecodeTransaction(
'3K7XxugEXv8CBQCaL1ZYB7cgYiCGE4THakb23hw3Ltv1XsYDCNctCEivhwCLvtyrfo3gsS9tS3CPqX6kYTe4WqZn',
{
richDecoding: true,
includeTokenMetadata: true,
includeNftMetadata: true
}
);
// Get human-readable insights
console.log(`Transaction type: ${decoded.summary.type}`);
console.log(`Total value: $${decoded.summary.totalValueUSD}`);
decoded.instructions.forEach(ix => {
console.log(`- ${ix.decoded.description}`);
});
```
### 2. Create a Token in 3 Lines
```typescript
const tokenResult = await sdk.createToken22TwoTx(wallet, {
name: 'My DeFi Token',
symbol: 'MDT',
supply: 1_000_000,
decimals: 6,
uri: 'https://my-metadata.com/token.json'
});
console.log(`Token launched: ${tokenResult.tokenAddress}`);
console.log(`Total cost: ${tokenResult.cost / 1e9} SOL`);
```
### 3. Mint an NFT Collection
```typescript
const nft = await sdk.createNFT(wallet, {
name: 'Genesis #001',
uri: 'https://my-nft-metadata.com/001.json',
royaltyBasisPoints: 500, // 5% royalty
attributes: [
{ trait_type: 'Rarity', value: 'Legendary' },
{ trait_type: 'Power', value: 100, display_type: 'number' }
]
});
console.log(`NFT minted: ${nft.assetAddress}`);
```
### 4. Analyze a Wallet Portfolio
```typescript
const portfolio = await sdk.getWalletPortfolio('8uZJDwaY1H1GmyQ7BGRB8ixNxHKB8fUCCjN3hAYvfvSL');
console.log(`Total value: $${portfolio.totalValueUSD}`);
console.log(`Token holdings: ${portfolio.tokens.length}`);
console.log(`NFT collections: ${portfolio.nfts.length}`);
console.log(`DeFi positions: ${portfolio.defiPositions.length}`);
```
## 🎯 V1 Specializations
### 1. **Rich Transaction Decoding** 🔍
Unlike basic RPC calls, GorbchainSDK provides:
- Human-readable instruction descriptions
- Automatic token/NFT metadata fetching
- Cross-program instruction correlation
- Transaction flow visualization
- Cost analysis in SOL and USD
**Supported Programs:**
- System Program (transfers, account creation)
- SPL Token & Token-2022 (all token operations)
- Metaplex (NFT minting, transfers, burns)
- Associated Token Account Program
- Custom program support via plugins
### 2. **Simplified Token Operations** 🪙
Create tokens with a single function call:
- Token22 program integration (latest standard)
- Automatic metadata upload
- Supply and decimal configuration
- Cost estimation before creation
- Transaction status tracking
### 3. **NFT Ecosystem Integration** 🎨
Full Metaplex Core support:
- Create NFTs with on-chain metadata
- Set royalties and creator shares
- Add unlimited attributes
- Batch minting capabilities
- Collection management
### 4. **Portfolio Intelligence** 📊
Track and analyze wallets:
- Real-time token balances
- NFT collection discovery
- DeFi position tracking
- Historical transaction analysis
- Performance metrics
## 📚 Complete API Reference
### Core SDK Class
```typescript
const sdk = new GorbchainSDK({
rpcEndpoint: string, // RPC endpoint URL
network: 'mainnet' | 'testnet' | 'devnet',
timeout?: number, // Request timeout (ms)
retries?: number, // Retry attempts
richDecoding?: {
enabled: boolean, // Enable rich decoding
includeTokenMetadata: boolean,
includeNftMetadata: boolean
}
});
```
### Transaction Decoding
```typescript
// Decode any transaction with rich insights
sdk.getAndDecodeTransaction(
signature: string,
options?: {
richDecoding?: boolean,
includeTokenMetadata?: boolean,
includeNftMetadata?: boolean
}
): Promise<DecodedTransaction>
// Decode individual instructions
sdk.decodeInstruction(instruction: TransactionInstruction): DecodedInstruction
// Batch decode multiple instructions
sdk.decodeInstructions(instructions: TransactionInstruction[]): DecodedInstruction[]
```
### Token Creation
```typescript
// Create token with 2 transactions (recommended)
sdk.createToken22TwoTx(
payer: Keypair,
params: {
name: string,
symbol: string,
supply: number,
decimals: number,
uri: string,
description?: string
}
): Promise<TokenCreationResult>
// Single transaction token creation (faster)
sdk.createToken22SingleTx(payer: Keypair, params: TokenParams): Promise<TokenCreationResult>
// Estimate costs before creation
sdk.estimateTokenCreationCost(params: TokenParams): Promise<number>
// Get comprehensive token information
sdk.getTokenInfo(mintAddress: string): Promise<TokenInfo>
```
### NFT Operations
```typescript
// Create NFT with Metaplex Core
sdk.createNFT(
wallet: Keypair,
params: {
name: string,
uri: string,
description?: string,
royaltyBasisPoints?: number,
creators?: Creator[],
attributes?: Attribute[]
}
): Promise<NFTCreationResult>
// Estimate NFT creation cost
sdk.estimateNFTCreationCost(params: NFTParams): Promise<number>
```
### Wallet & Balance Management
```typescript
// Check if wallet has sufficient balance
sdk.checkSufficientBalance(
address: PublicKey,
requiredAmount: number
): Promise<BalanceCheckResult>
// Get wallet portfolio analysis
sdk.getWalletPortfolio(address: string): Promise<Portfolio>
```
### Network Operations
```typescript
// Check network health
sdk.getNetworkHealth(): Promise<NetworkHealth>
// Get current slot
sdk.getCurrentSlot(): Promise<number>
// Get block height
sdk.getBlockHeight(): Promise<number>
```
### 🔐 Cryptography Operations
#### Personal Encryption
```typescript
// Encrypt data with private key
encryptPersonal(
data: string | Buffer,
privateKey: string,
options?: {
compress?: boolean,
metadata?: Record<string, any>
}
): Promise<PersonalEncryptionResult>
// Decrypt personal data
decryptPersonalString(
encryptedResult: PersonalEncryptionResult,
privateKey: string
): Promise<string>
decryptPersonalBuffer(
encryptedResult: PersonalEncryptionResult,
privateKey: string
): Promise<Buffer>
```
#### Direct Encryption
```typescript
// Encrypt for specific recipient
encryptDirect(
data: string | Buffer,
recipientPublicKey: string,
senderPrivateKey: string,
options?: {
compress?: boolean,
includeMetadata?: boolean
}
): Promise<DirectEncryptionResult>
// Decrypt from sender
decryptDirectString(
encryptedResult: DirectEncryptionResult,
recipientPrivateKey: string
): Promise<string>
decryptDirectBuffer(
encryptedResult: DirectEncryptionResult,
recipientPrivateKey: string
): Promise<Buffer>
```
#### Group & Signature-Based Encryption
```typescript
// Create signature group
createSignatureGroup(
groupName: string,
creatorPrivateKey: string,
initialMembers?: GroupMember[],
options?: {
allowDynamicMembership?: boolean,
maxMembers?: number,
requireSignatureVerification?: boolean
}
): Promise<SignatureGroup>
// Encrypt for group
encryptForSignatureGroup(
data: string,
groupMetadata: SignatureGroup,
senderPrivateKey: string,
senderPublicKey: string,
options?: EncryptionOptions
): Promise<GroupEncryptionResult>
// Add member to group
addMemberToSignatureGroup(
groupMetadata: SignatureGroup,
newMember: { publicKey: string, role: MemberRole },
authorizerPrivateKey: string,
authorizerPublicKey: string
): Promise<SignatureGroup>
// Remove member from group
removeMemberFromSignatureGroup(
groupMetadata: SignatureGroup,
memberPublicKey: string,
authorizerPrivateKey: string,
authorizerPublicKey: string,
rotateKeys?: boolean
): Promise<SignatureGroup>
```
#### Shared Key Management
```typescript
// Create shared key
SharedKeyManager.createSharedKey(
keyMetadata: {
name: string,
purpose: string,
creator: string
},
initialRecipients: SharedKeyRecipient[],
creatorPrivateKey: string
): Promise<SharedKeyResult>
// Encrypt with shared key
SharedKeyManager.encryptWithSharedKey(
data: string,
keyId: string,
senderPrivateKey: string,
senderPublicKey: string
): Promise<SharedKeyEncryptionResult>
// Add recipients to shared key
SharedKeyManager.addRecipientsToSharedKey(
keyId: string,
newRecipients: SharedKeyRecipient[],
authorizerPrivateKey: string,
authorizerPublicKey: string
): Promise<SharedKeyResult>
// Transition personal encryption to shared key
SharedKeyManager.transitionToSharedKey(
originalEncryptionResult: PersonalEncryptionResult | DirectEncryptionResult,
transitionRequest: TransitionRequest
): Promise<SharedKeyTransitionResult>
```
#### Scalable Encryption Contexts
```typescript
// Create scalable context
ScalableEncryptionManager.createEncryptionContext(
contextName: string,
purpose: string,
initialRecipient: string,
creatorPrivateKey: string,
options?: {
autoTransitionThreshold?: number,
defaultPermissions?: ContextPermissions
}
): Promise<{ manager: ScalableEncryptionManager, context: EncryptionContext }>
// Encrypt in context (auto-scales method)
ScalableEncryptionManager.encryptInContext(
contextId: string,
data: string,
senderPrivateKey: string
): Promise<ContextEncryptionResult>
// Add recipients to context
ScalableEncryptionManager.addRecipientsToContext(
contextId: string,
newRecipients: string[],
authorizerPrivateKey: string,
authorizerPublicKey: string
): Promise<EncryptionContext>
```
#### Digital Signatures
```typescript
// Sign data
signData(
data: string,
privateKey: string
): string
// Verify signature
verifySignature(
data: string,
signature: string,
publicKey: string
): boolean
// Sign with metadata
signWithMetadata(
data: string,
privateKey: string,
metadata: Record<string, any>
): SignatureResult
// Verify with metadata
verifyWithMetadata(
signatureResult: SignatureResult,
publicKey: string
): VerificationResult
```
## 🏗️ Framework Integration
### React / Next.js
```typescript
import { GorbchainSDK } from '@gorbchain-xyz/chaindecode';
import { useWallet } from '@solana/wallet-adapter-react';
export function TokenLauncher() {
const { publicKey, signTransaction } = useWallet();
const [loading, setLoading] = useState(false);
const launchToken = async () => {
setLoading(true);
const sdk = new GorbchainSDK({ rpcEndpoint: process.env.NEXT_PUBLIC_RPC });
try {
const result = await sdk.createToken22TwoTx(wallet, {
name: 'My Token',
symbol: 'MTK',
supply: 1_000_000,
decimals: 9,
uri: 'https://metadata.com/token.json'
});
console.log('Token created:', result.tokenAddress);
} finally {
setLoading(false);
}
};
return (
<button onClick={launchToken} disabled={loading}>
{loading ? 'Creating...' : 'Launch Token'}
</button>
);
}
```
### Vue.js
```vue
<template>
<div>
<button @click="decodeTransaction" :disabled="loading">
Decode Transaction
</button>
<div v-if="decoded">
<h3>Transaction Summary</h3>
<p>Type: {{ decoded.summary.type }}</p>
<p>Value: ${{ decoded.summary.totalValueUSD }}</p>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue';
import { GorbchainSDK } from '@gorbchain-xyz/chaindecode';
const loading = ref(false);
const decoded = ref(null);
const decodeTransaction = async () => {
loading.value = true;
const sdk = new GorbchainSDK({ rpcEndpoint: import.meta.env.VITE_RPC });
try {
decoded.value = await sdk.getAndDecodeTransaction('signature_here', {
richDecoding: true,
includeTokenMetadata: true
});
} finally {
loading.value = false;
}
};
</script>
```
### Node.js Backend
```typescript
import express from 'express';
import { GorbchainSDK } from '@gorbchain-xyz/chaindecode';
const app = express();
const sdk = new GorbchainSDK({ rpcEndpoint: process.env.RPC_ENDPOINT });
app.get('/api/decode/:signature', async (req, res) => {
try {
const decoded = await sdk.getAndDecodeTransaction(req.params.signature, {
richDecoding: true
});
res.json(decoded);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.post('/api/estimate-token-cost', async (req, res) => {
const cost = await sdk.estimateTokenCreationCost(req.body);
res.json({ costInSOL: cost / 1e9 });
});
```
## 🚀 Real-World Use Cases
### 1. **DeFi Dashboard**
```typescript
// Monitor user's DeFi positions across protocols
const positions = await sdk.getWalletPortfolio(userAddress);
const defiValue = positions.defiPositions.reduce((sum, pos) => sum + pos.valueUSD, 0);
```
### 2. **NFT Marketplace**
```typescript
// List user's NFTs with metadata
const portfolio = await sdk.getWalletPortfolio(userAddress);
const nfts = portfolio.nfts.map(nft => ({
name: nft.metadata.name,
image: nft.metadata.image,
attributes: nft.metadata.attributes,
floorPrice: nft.floorPriceUSD
}));
```
### 3. **Token Launchpad**
```typescript
// Launch token with automatic liquidity pool creation
const token = await sdk.createToken22TwoTx(wallet, tokenParams);
// Add liquidity using Raydium/Orca SDK
```
### 4. **Transaction Explorer**
```typescript
// Build a better Solscan
const tx = await sdk.getAndDecodeTransaction(signature);
// Display human-readable transaction flow
```
### 5. **Portfolio Tracker**
```typescript
// Track portfolio performance over time
const portfolio = await sdk.getWalletPortfolio(address);
const totalValue = portfolio.totalValueUSD;
const topHoldings = portfolio.tokens.sort((a, b) => b.valueUSD - a.valueUSD).slice(0, 10);
```
### 6. **Secure Communication App**
```typescript
// End-to-end encrypted messaging
const encrypted = await encryptDirect(
'Secret message',
recipientPublicKey,
senderPrivateKey
);
// Group chat with dynamic membership
const group = await createSignatureGroup('Team Chat', creatorPrivateKey);
const groupMessage = await encryptForSignatureGroup(
'Team update',
group,
senderPrivateKey,
senderPublicKey
);
```
### 7. **Document Management System**
```typescript
// Shared document encryption
const sharedKey = await sharedKeyManager.createSharedKey(
{ name: 'Legal Documents', purpose: 'Contract management' },
[
{ publicKey: lawyer1, permissions: { canDecrypt: true, canEncrypt: true, canShare: true }},
{ publicKey: client1, permissions: { canDecrypt: true, canEncrypt: false, canShare: false }}
],
adminPrivateKey
);
const encryptedDoc = await sharedKeyManager.encryptWithSharedKey(
documentContent,
sharedKey.keyId,
senderPrivateKey,
senderPublicKey
);
```
## 📋 Version History & Changelog
### V1.3.0+ (Latest) - Cryptography Suite Release
**Released**: December 2024
**🔐 NEW FEATURES:**
- **Personal Encryption**: Private key-based encryption/decryption
- **Direct Encryption**: Public key encryption between parties with ECDH
- **Group Encryption**: Multi-recipient encryption with role-based access control
- **Signature Groups**: Dynamic membership with signature-based verification
- **Shared Key Management**: Managed encryption keys with granular permissions
- **Scalable Contexts**: Auto-scaling from direct to group encryption
- **Digital Signatures**: Ed25519 signatures with metadata support
- **Crypto Playground**: Interactive testing environment for all crypto features
**🌐 RPC ENHANCEMENTS:**
- Advanced connection pooling and health monitoring
- Exponential backoff retry logic with custom retry conditions
- Real-time network status monitoring
- Enhanced caching with TTL and size limits
- Connection-specific error handling and recovery
**🏗️ DEVELOPER EXPERIENCE:**
- TypeScript-first API with full type safety
- Interactive playground for testing all features
- Comprehensive documentation with real-world examples
- Framework integration guides for React, Vue, Next.js
### V1.2.0 - Enhanced Analytics
**Released**: October 2024
- Portfolio intelligence improvements
- Cross-program transaction correlation
- Enhanced token metadata fetching
- Performance optimizations
### V1.1.0 - Token & NFT Operations
**Released**: August 2024
- Token22 program integration
- Metaplex Core NFT support
- Batch operation capabilities
- Cost estimation features
### V1.0.0 - Initial Release
**Released**: June 2024
- Core transaction decoding functionality
- Basic RPC connection management
- Fundamental blockchain analysis tools
## 🔧 Dependencies & Requirements
### Core Dependencies
```json
{
"@solana/web3.js": "^1.95.0+",
"tweetnacl": "^1.0.3",
"buffer": "^6.0.3"
}
```
### System Requirements
- **Node.js**: 16+ (18+ recommended)
- **TypeScript**: 4.5+ (5.0+ recommended)
- **Browser Support**: Chrome 90+, Firefox 88+, Safari 14+
- **Memory**: 512MB+ available RAM
- **Network**: Reliable internet connection for RPC calls
### Optional Dependencies
- **React**: 18+ for React components
- **Vue**: 3+ for Vue components
- **Next.js**: 13+ for SSR/SSG support
## ⚡ Performance Optimizations
### Caching Strategy
```typescript
const sdk = new GorbchainSDK({
rpcEndpoint: 'https://api.mainnet-beta.solana.com',
cache: {
enabled: true,
ttl: 60000, // 1 minute
maxSize: 1000
}
});
```
### Batch Operations
```typescript
// Decode multiple transactions efficiently
const signatures = ['sig1', 'sig2', 'sig3'];
const decoded = await Promise.all(
signatures.map(sig => sdk.getAndDecodeTransaction(sig))
);
```
### Connection Pooling
```typescript
// Use connection pool for high-throughput applications
const sdk = new GorbchainSDK({
rpcEndpoint: 'https://api.mainnet-beta.solana.com',
connectionPool: {
size: 10,
minConnections: 2,
maxConnections: 20
}
});
```
## 🔧 Advanced Features
### Custom Instruction Decoders
```typescript
import { DecoderRegistry } from '@gorbchain-xyz/chaindecode';
// Add support for your custom program
const registry = new DecoderRegistry();
registry.register('MyDeFiProtocol', 'ProgramID...', (instruction) => ({
type: 'swap',
programId: instruction.programId,
data: decodeSwapData(instruction.data),
accounts: mapSwapAccounts(instruction.accounts)
}));
const sdk = new GorbchainSDK({
rpcEndpoint: 'https://api.mainnet-beta.solana.com',
customDecoders: registry
});
```
### Webhook Integration
```typescript
// Monitor addresses for new transactions
sdk.watchAddress('8uZJDwaY1H1GmyQ7BGRB8ixNxHKB8fUCCjN3hAYvfvSL', async (tx) => {
const decoded = await sdk.getAndDecodeTransaction(tx.signature);
// Send to webhook
await fetch('https://your-webhook.com', {
method: 'POST',
body: JSON.stringify(decoded)
});
});
```
### Error Recovery
```typescript
const sdk = new GorbchainSDK({
rpcEndpoint: 'https://api.mainnet-beta.solana.com',
retries: 3,
retryDelay: 1000,
onError: (error, attempt) => {
console.log(`Attempt ${attempt} failed:`, error.message);
}
});
```
## 🛡️ Security Best Practices
### General Security
1. **Never expose private keys in frontend code**
2. **Use environment variables for RPC endpoints**
3. **Implement rate limiting for API endpoints**
4. **Validate all user inputs before processing**
5. **Use secure key management solutions**
### Cryptography Security
6. **Generate keys with cryptographically secure randomness**
7. **Never reuse nonces or ephemeral keys**
8. **Implement forward secrecy with key rotation**
9. **Use signature verification for group access control**
10. **Regularly audit and rotate shared keys**
11. **Implement proper access controls for shared key permissions**
12. **Store encrypted data with integrity checks**
### Production Deployment
13. **Use HTTPS for all network communications**
14. **Implement proper error handling without exposing sensitive details**
15. **Monitor for unusual encryption/decryption patterns**
16. **Use hardware security modules (HSMs) for production key storage**
## 📊 Benchmarks
### Core Operations
| Operation | GorbchainSDK V1.3+ | Raw Web3.js | Improvement |
|-----------|-------------------|-------------|-------------|
| Transaction Decoding | 45ms | 380ms | 8.4x faster |
| Token Creation | 2.1s | 5.8s | 2.7x faster |
| NFT Minting | 1.8s | 4.2s | 2.3x faster |
| Portfolio Analysis | 120ms | 850ms | 7.1x faster |
### Cryptography Operations
| Operation | Performance | Memory Usage | Notes |
|-----------|-------------|--------------|-------|
| Personal Encryption | ~15ms | 2KB | AES-256-GCM |
| Direct Encryption | ~25ms | 3KB | ECDH + AES-256-GCM |
| Group Encryption (10 members) | ~85ms | 8KB | Shared key distribution |
| Signature Verification | ~5ms | 1KB | Ed25519 |
| Key Generation | ~8ms | 1KB | Cryptographically secure |
### Scalability Tests
| Recipients | Direct Encryption | Shared Key | Auto-Scale Choice |
|------------|------------------|------------|-------------------|
| 1 | 25ms | N/A | Direct |
| 2 | 35ms | N/A | Direct |
| 3 | 45ms | 35ms | **Shared Key** |
| 10 | 150ms | 85ms | **Shared Key** |
| 100 | 1.5s | 95ms | **Shared Key** |
*Benchmarks performed on mainnet-beta with standard RPC endpoints and Node.js 18+*
## 🤝 Contributing
We welcome contributions! See our [Contributing Guide](CONTRIBUTING.md) for details.
### Development Setup
```bash
git clone https://github.com/gorbchain/sdk.git
cd sdk
npm install
npm run build
npm test
```
## 📄 License
MIT License - see [LICENSE](LICENSE) for details.
## 🔗 Resources
- **🌐 Website**: [https://gorbchain.xyz](https://gorbchain.xyz)
- **📚 Documentation**: [https://docs.gorbchain.xyz](https://docs.gorbchain.xyz)
- **🚀 Token Launchpad**: [https://launch.gorbchain.xyz](https://launch.gorbchain.xyz)
- **💬 Discord**: [Join our community](https://discord.gg/gorbchain)
- **🐦 Twitter**: [@GorbChain](https://twitter.com/GorbChain)
- **📦 NPM**: [@gorbchain-xyz/chaindecode](https://www.npmjs.com/package/@gorbchain-xyz/chaindecode)
---
**Built by developers, for developers** ❤️ Stop writing boilerplate. Start shipping features.
*GorbchainSDK V1 - Where every line of code counts.*