Gathering detailed insights and metrics for bond-wallet-sdk
Gathering detailed insights and metrics for bond-wallet-sdk
Gathering detailed insights and metrics for bond-wallet-sdk
Gathering detailed insights and metrics for bond-wallet-sdk
The Bond Wallet SDK is a TypeScript/JavaScript library that provides a simple and powerful interface to interact with Bond Protocol
npm install bond-wallet-sdk
Typescript
Module System
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
11 Commits
1 Branches
1 Contributors
Updated on Jul 01, 2025
Latest Version
0.0.2
Package Id
bond-wallet-sdk@0.0.2
Unpacked Size
445.77 kB
Size
79.79 kB
File Count
16
NPM Version
10.9.2
Node Version
22.15.0
Published on
Jun 30, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
The Bond Wallet SDK is a TypeScript/JavaScript library that provides a simple and powerful interface to interact with Bond Protocol. It abstracts the complexity of cross-chain operations and ERC-4337 account abstraction, enabling developers to build seamless multi-chain applications.
1npm install bond-wallet-sdk
1import { BondWallet } from "bond-wallet-js"; 2import { createWalletClient, http } from "viem"; 3import { privateKeyToAccount } from "viem/accounts"; 4import { sepolia } from "viem/chains"; 5 6// Create wallet client (using viem) 7const account = privateKeyToAccount("0x..."); 8const walletClient = createWalletClient({ 9 account, 10 chain: sepolia, 11 transport: http() 12}); 13 14// Initialize Bond Wallet 15const bondWallet = new BondWallet(walletClient); 16 17// Get smart account address 18const address = await bondWallet.getAddress(); 19console.log("Bond Smart Account:", address);
Before interacting with any chain you must activate your address. This will make your Bond experience smooth
1// Activate sepolia address, repeat this step for other chains 2const response = await bondWallet.activate("sepolia"); 3console.log(response);
1// Check unified balance 2const balance = await bondWallet.unifiedBalance("USDC"); 3console.log("Total USDC across all chains:", balance.balance); 4 5// Create cross-chain intent 6const intent = await bondWallet.intent.direct({ 7 token: "USDC", 8 source: [ 9 { amount: "10", chain: "sepolia" }, 10 { amount: "5", chain: "polygon_amoy" } 11 ], 12 destChain: "avalanche_fuji", 13 recipient: "0x742d35Cc6634C0532925a3b8D4B9f4B3D7b4bE4B", 14 amount: "15" 15}); 16 17// Execute the intent 18const userOpHash = await intent.send(); 19console.log("Intent submitted:", userOpHash);
1constructor(walletClient: WalletClient)
Parameters:
walletClient
: A viem WalletClient instanceExample:
1const bondWallet = new BondWallet(walletClient);
getAddress()
Returns the Bond Smart Account address.
1async getAddress(): Promise<string>
Returns: Promise<string>
- The smart account address
Example:
1const address = await bondWallet.getAddress(); 2console.log(address); // "0x..."
unifiedBalance(token)
Get unified token balance across all supported chains.
1async unifiedBalance(token: string): Promise<UnifiedBalanceResponse>
Parameters:
token
: Token symbol (e.g., "USDC")Returns: Promise<UnifiedBalanceResponse>
1interface UnifiedBalanceResponse { 2 balance: number; // Total unified balance 3 fragmented: Array<{ // Per-chain breakdown 4 chain: string; 5 balance: number; 6 }>; 7 chainBalance: number; // Current chain balance 8}
Example:
1const balance = await bondWallet.unifiedBalance("USDC"); 2console.log(`Total: ${balance.balance} USDC`); 3console.log(`On current chain: ${balance.chainBalance} USDC`); 4 5balance.fragmented.forEach(({ chain, balance }) => { 6 console.log(`${chain}: ${balance} USDC`); 7});
sendUserOperation(params)
Send a standard user operation (non-intent transaction).
1async sendUserOperation(params: UserOperationParams): Promise<string>
Parameters:
1interface UserOperationParams { 2 to: string; // Target contract address 3 data: string; // Encoded function data 4 value?: bigint; // ETH value (optional) 5}
Returns: Promise<string>
- User operation hash
Example:
1const userOpHash = await bondWallet.sendUserOperation({ 2 to: "0x...", 3 data: "0x...", 4 value: parseEther("0.1") 5});
bondWallet.intent.direct(params)
Create a direct cross-chain intent.
1async direct(params: DirectIntentParams): Promise<Intent>
Parameters:
1interface DirectIntentParams { 2 token: string; // Token symbol 3 source: Array<{ // Source chain configurations 4 amount: string; // Amount on this chain 5 chain: string; // Chain identifier 6 }>; 7 destChain: string; // Destination chain 8 recipient: string; // Recipient address 9 amount: string; // Total amount to send 10}
Returns: Promise<Intent>
- Intent object
Example:
1const intent = await bondWallet.intent.direct({ 2 token: "USDC", 3 source: [ 4 { amount: "25", chain: "sepolia" }, 5 { amount: "25", chain: "polygon_amoy" } 6 ], 7 destChain: "avalanche_fuji", 8 recipient: "0x742d35Cc6634C0532925a3b8D4B9f4B3D7b4bE4B", 9 amount: "50" 10});
The Intent object returned by intent.direct()
provides methods to interact with the created intent.
data
Get the raw encoded intent data.
1readonly data: string
Example:
1const intentData = intent.data; 2console.log("Intent bytes:", intentData);
getFees()
Get fee estimate for executing the intent.
1async getFees(): Promise<bigint>
Returns: Promise<bigint>
- Fee amount in token units
Example:
1const fees = await intent.getFees(); 2console.log(`Estimated fees: ${formatUnits(fees, 6)} USDC`);
send()
Execute the intent and submit it to the protocol.
1async send(): Promise<string>
Returns: Promise<string>
- User operation hash
Example:
1try { 2 const userOpHash = await intent.send(); 3 console.log("Intent submitted successfully:", userOpHash); 4} catch (error) { 5 console.error("Failed to send intent:", error); 6}
BondWallet.buildContract(params)
Static utility function to encode contract function calls.
1static async buildContract(params: BuildContractParams): Promise<string>
Parameters:
1interface BuildContractParams { 2 abi: any[]; // Contract ABI 3 functionName: string; // Function name to call 4 args: any[]; // Function arguments 5}
Returns: Promise<string>
- Encoded function data
Example:
1const ERC20_ABI = [ 2 { 3 "inputs": [ 4 {"name": "spender", "type": "address"}, 5 {"name": "amount", "type": "uint256"} 6 ], 7 "name": "approve", 8 "outputs": [{"name": "", "type": "bool"}], 9 "type": "function" 10 } 11]; 12 13const data = await BondWallet.buildContract({ 14 abi: ERC20_ABI, 15 functionName: "approve", 16 args: ["0x742d35Cc6634C0532925a3b8D4B9f4B3D7b4bE4B", parseUnits("100", 6)] 17}); 18 19await bondWallet.sendUserOperation({ 20 to: "0x...", // USDC token address 21 data: data 22});
For advanced users who need to work with custom chain configurations:
1// Custom wallet client with specific chain 2const customWalletClient = createWalletClient({ 3 account: privateKeyToAccount(privateKey), 4 chain: { 5 id: 11155111, 6 name: 'Sepolia', 7 network: 'sepolia', 8 nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 }, 9 rpcUrls: { 10 default: { http: ['https://sepolia.infura.io/v3/YOUR_KEY'] }, 11 public: { http: ['https://sepolia.infura.io/v3/YOUR_KEY'] } 12 } 13 }, 14 transport: http() 15}); 16 17const bondWallet = new BondWallet(customWalletClient);
1// Execute multiple operations in sequence 2async function batchOperations() { 3 // First approve token spending 4 const approveData = await BondWallet.buildContract({ 5 abi: ERC20_ABI, 6 functionName: "approve", 7 args: [PROTOCOL_ADDRESS, parseUnits("100", 6)] 8 }); 9 10 await bondWallet.sendUserOperation({ 11 to: USDC_ADDRESS, 12 data: approveData 13 }); 14 15 // Then create and send intent 16 const intent = await bondWallet.intent.direct({ 17 token: "USDC", 18 source: [{ amount: "50", chain: "sepolia" }], 19 destChain: "polygon_amoy", 20 recipient: "0x...", 21 amount: "50" 22 }); 23 24 const userOpHash = await intent.send(); 25 return userOpHash; 26}
1// Check fees before execution 2async function optimizedIntentExecution() { 3 const intent = await bondWallet.intent.direct({ 4 token: "USDC", 5 source: [ 6 { amount: "30", chain: "sepolia" }, 7 { amount: "20", chain: "polygon_amoy" } 8 ], 9 destChain: "avalanche_fuji", 10 recipient: "0x...", 11 amount: "50" 12 }); 13 14 const estimatedFees = await intent.getFees(); 15 const feesInUSDC = Number(formatUnits(estimatedFees, 6)); 16 17 console.log(`Estimated fees: ${feesInUSDC} USDC`); 18 19 // Only proceed if fees are reasonable 20 if (feesInUSDC < 5) { // Less than $5 in fees 21 return await intent.send(); 22 } else { 23 throw new Error(`Fees too high: ${feesInUSDC} USDC`); 24 } 25}
1import { BondWallet } from "bond-wallet-js"; 2import { createWalletClient, http, parseUnits, formatUnits } from "viem"; 3import { privateKeyToAccount } from "viem/accounts"; 4import { sepolia } from "viem/chains"; 5 6async function simpleCrossChainTransfer() { 7 // Setup 8 const account = privateKeyToAccount(process.env.PRIVATE_KEY!); 9 const walletClient = createWalletClient({ 10 account, 11 chain: sepolia, 12 transport: http() 13 }); 14 15 const bondWallet = new BondWallet(walletClient); 16 17 try { 18 // Check balance 19 const balance = await bondWallet.unifiedBalance("USDC"); 20 console.log("Available USDC:", balance.balance); 21 22 if (balance.balance < 10) { 23 throw new Error("Insufficient balance"); 24 } 25 26 // Create intent 27 const intent = await bondWallet.intent.direct({ 28 token: "USDC", 29 source: [ 30 { amount: "10", chain: "sepolia" } 31 ], 32 destChain: "polygon_amoy", 33 recipient: "0x742d35Cc6634C0532925a3b8D4B9f4B3D7b4bE4B", 34 amount: "10" 35 }); 36 37 // Check fees 38 const fees = await intent.getFees(); 39 console.log("Fees:", formatUnits(fees, 6), "USDC"); 40 41 // Execute 42 const userOpHash = await intent.send(); 43 console.log("Success! UserOp hash:", userOpHash); 44 45 } catch (error) { 46 console.error("Error:", error); 47 } 48} 49 50simpleCrossChainTransfer();
1async function multiChainAggregation() { 2 const bondWallet = new BondWallet(walletClient); 3 4 // Check fragmented balances 5 const balance = await bondWallet.unifiedBalance("USDC"); 6 console.log("Fragmented balances:"); 7 balance.fragmented.forEach(({ chain, balance }) => { 8 console.log(` ${chain}: ${balance} USDC`); 9 }); 10 11 // Aggregate from multiple chains 12 const intent = await bondWallet.intent.direct({ 13 token: "USDC", 14 source: [ 15 { amount: "15", chain: "sepolia" }, 16 { amount: "10", chain: "avalanche_fuji" }, 17 { amount: "25", chain: "arbitrum_sepolia" } 18 ], 19 destChain: "polygon_amoy", 20 recipient: "0x742d35Cc6634C0532925a3b8D4B9f4B3D7b4bE4B", 21 amount: "50" 22 }); 23 24 console.log("Intent data:", intent.data); 25 26 const userOpHash = await intent.send(); 27 console.log("Multi-chain aggregation completed:", userOpHash); 28}
1async function defiIntegration() { 2 const bondWallet = new BondWallet(walletClient); 3 4 // First, aggregate liquidity to the DeFi protocol's chain 5 const aggregationIntent = await bondWallet.intent.direct({ 6 token: "USDC", 7 source: [ 8 { amount: "50", chain: "sepolia" }, 9 { amount: "30", chain: "polygon_amoy" } 10 ], 11 destChain: "avalanche_fuji", // DeFi protocol is on Avalanche 12 recipient: await bondWallet.getAddress(), // Send to self 13 amount: "80" 14 }); 15 16 await aggregationIntent.send(); 17 18 // Wait for settlement (in real app, you'd monitor the transaction) 19 await new Promise(resolve => setTimeout(resolve, 60000)); // 1 minute 20 21 // Then interact with DeFi protocol 22 const stakeData = await BondWallet.buildContract({ 23 abi: STAKING_CONTRACT_ABI, 24 functionName: "stake", 25 args: [parseUnits("80", 6)] 26 }); 27 28 await bondWallet.sendUserOperation({ 29 to: STAKING_CONTRACT_ADDRESS, 30 data: stakeData 31 }); 32 33 console.log("Successfully aggregated and staked tokens!"); 34}
1async function portfolioRebalancing() { 2 const bondWallet = new BondWallet(walletClient); 3 4 // Get current portfolio distribution 5 const balance = await bondWallet.unifiedBalance("USDC"); 6 7 // Define target allocation (40% on Polygon, 30% on Arbitrum, 30% on Avalanche) 8 const totalBalance = balance.balance; 9 const targetAllocations = { 10 "polygon_amoy": totalBalance * 0.4, 11 "arbitrum_sepolia": totalBalance * 0.3, 12 "avalanche_fuji": totalBalance * 0.3 13 }; 14 15 // Calculate rebalancing needs 16 const rebalanceIntents = []; 17 18 for (const [targetChain, targetAmount] of Object.entries(targetAllocations)) { 19 const currentAmount = balance.fragmented.find( 20 f => f.chain === targetChain 21 )?.balance || 0; 22 23 const deficit = targetAmount - currentAmount; 24 25 if (deficit > 1) { // Only rebalance if deficit > 1 USDC 26 // Find source chains with excess 27 const sources = balance.fragmented 28 .filter(f => f.chain !== targetChain && f.balance > deficit) 29 .slice(0, 2) // Max 2 sources 30 .map(f => ({ 31 amount: Math.min(f.balance, deficit / 2).toString(), 32 chain: f.chain 33 })); 34 35 if (sources.length > 0) { 36 const intent = await bondWallet.intent.direct({ 37 token: "USDC", 38 source: sources, 39 destChain: targetChain, 40 recipient: await bondWallet.getAddress(), 41 amount: sources.reduce((sum, s) => sum + parseFloat(s.amount), 0).toString() 42 }); 43 44 rebalanceIntents.push(intent); 45 } 46 } 47 } 48 49 // Execute all rebalancing intents 50 const results = await Promise.all( 51 rebalanceIntents.map(intent => intent.send()) 52 ); 53 54 console.log(`Executed ${results.length} rebalancing intents:`, results); 55}
1// Network errors 2try { 3 const balance = await bondWallet.unifiedBalance("USDC"); 4} catch (error) { 5 if (error.code === 'NETWORK_ERROR') { 6 console.error("Network connection failed:", error.message); 7 } 8} 9 10// Invalid parameters 11try { 12 const intent = await bondWallet.intent.direct({ 13 token: "INVALID_TOKEN", 14 source: [{ amount: "10", chain: "invalid_chain" }], 15 destChain: "sepolia", 16 recipient: "0x...", 17 amount: "10" 18 }); 19} catch (error) { 20 if (error.code === 'INVALID_PARAMETER') { 21 console.error("Invalid parameter:", error.message); 22 } 23} 24 25// Insufficient funds 26try { 27 const userOpHash = await intent.send(); 28} catch (error) { 29 if (error.code === 'INSUFFICIENT_FUNDS') { 30 console.error("Not enough tokens or gas:", error.message); 31 } 32}
1async function robustIntentExecution(intentParams) { 2 const MAX_RETRIES = 3; 3 let retries = 0; 4 5 while (retries < MAX_RETRIES) { 6 try { 7 // Check balance first 8 const balance = await bondWallet.unifiedBalance(intentParams.token); 9 const requiredAmount = parseFloat(intentParams.amount); 10 11 if (balance.balance < requiredAmount) { 12 throw new Error(`Insufficient balance: need ${requiredAmount}, have ${balance.balance}`); 13 } 14 15 // Create intent 16 const intent = await bondWallet.intent.direct(intentParams); 17 18 // Check fees 19 const fees = await intent.getFees(); 20 const feesInToken = Number(formatUnits(fees, 6)); 21 22 if (feesInToken > requiredAmount * 0.1) { // Fees > 10% of amount 23 throw new Error(`Fees too high: ${feesInToken} ${intentParams.token}`); 24 } 25 26 // Execute 27 const userOpHash = await intent.send(); 28 console.log("Intent executed successfully:", userOpHash); 29 return userOpHash; 30 31 } catch (error) { 32 retries++; 33 console.error(`Attempt ${retries} failed:`, error.message); 34 35 if (retries < MAX_RETRIES) { 36 // Exponential backoff 37 await new Promise(resolve => 38 setTimeout(resolve, Math.pow(2, retries) * 1000) 39 ); 40 } else { 41 throw error; 42 } 43 } 44 } 45}
The SDK is built with TypeScript and provides comprehensive type definitions.
1// Import types 2import { 3 BondWallet, 4 UnifiedBalanceResponse, 5 DirectIntentParams, 6 Intent, 7 UserOperationParams, 8 BuildContractParams 9} from "bond-wallet-js"; 10 11// Type-safe usage 12const balance: UnifiedBalanceResponse = await bondWallet.unifiedBalance("USDC"); 13 14const intentParams: DirectIntentParams = { 15 token: "USDC", 16 source: [{ amount: "10", chain: "sepolia" }], 17 destChain: "polygon_amoy", 18 recipient: "0x...", 19 amount: "10" 20}; 21 22const intent: Intent = await bondWallet.intent.direct(intentParams);
1// Custom token type 2type SupportedToken = "USDC" | "USDT" | "DAI"; 3 4// Custom chain type 5type SupportedChain = "sepolia" | "polygon_amoy" | "avalanche_fuji" | "arbitrum_sepolia"; 6 7// Type-safe helper function 8async function createTypedIntent<T extends SupportedToken>( 9 token: T, 10 amount: string, 11 recipient: string 12): Promise<Intent> { 13 return bondWallet.intent.direct({ 14 token, 15 source: [{ amount, chain: "sepolia" }], 16 destChain: "polygon_amoy", 17 recipient, 18 amount 19 }); 20}
Always check balances before creating intents:
1async function safeIntentCreation(params: DirectIntentParams) { 2 const balance = await bondWallet.unifiedBalance(params.token); 3 const requiredAmount = parseFloat(params.amount); 4 5 if (balance.balance < requiredAmount) { 6 throw new Error(`Insufficient balance: ${balance.balance} < ${requiredAmount}`); 7 } 8 9 return bondWallet.intent.direct(params); 10}
Always estimate fees before execution:
1async function feeAwareExecution(intent: Intent) { 2 const fees = await intent.getFees(); 3 const feesInUSDC = Number(formatUnits(fees, 6)); 4 5 console.log(`Estimated fees: $${feesInUSDC}`); 6 7 // Only proceed if fees are reasonable 8 if (feesInUSDC > 10) { 9 throw new Error("Fees too high"); 10 } 11 12 return intent.send(); 13}
Implement proper error recovery:
1async function resilientExecution(params: DirectIntentParams) { 2 try { 3 const intent = await bondWallet.intent.direct(params); 4 return await intent.send(); 5 } catch (error) { 6 // Log error for debugging 7 console.error("Intent execution failed:", error); 8 9 // Try alternative approach 10 if (error.code === 'INSUFFICIENT_LIQUIDITY') { 11 // Maybe try with different source chains 12 const alternativeParams = { ...params }; 13 // Modify params... 14 return bondWallet.intent.direct(alternativeParams); 15 } 16 17 throw error; 18 } 19}
Properly manage wallet connections:
1class BondWalletManager { 2 private bondWallet: BondWallet | null = null; 3 4 async connect(walletClient: WalletClient) { 5 this.bondWallet = new BondWallet(walletClient); 6 7 // Verify connection 8 try { 9 await this.bondWallet.getAddress(); 10 console.log("Connected to Bond Protocol"); 11 } catch (error) { 12 this.bondWallet = null; 13 throw new Error("Failed to connect to Bond Protocol"); 14 } 15 } 16 17 async disconnect() { 18 this.bondWallet = null; 19 } 20 21 get wallet() { 22 if (!this.bondWallet) { 23 throw new Error("Not connected to Bond Protocol"); 24 } 25 return this.bondWallet; 26 } 27}
Problem: Wallet client configured with unsupported chain.
Solution:
1// Ensure you're using supported chains 2const supportedChains = { 3 sepolia: 11155111, 4 polygon_amoy: 80002, 5 avalanche_fuji: 43113, 6 arbitrum_sepolia: 421614 7}; 8 9// Use correct chain configuration 10const walletClient = createWalletClient({ 11 account, 12 chain: sepolia, // Use viem's chain constants 13 transport: http() 14});
Problem: Token not approved for spending.
Solution:
1// Approve token spending first 2const approveData = await BondWallet.buildContract({ 3 abi: ERC20_ABI, 4 functionName: "approve", 5 args: [PROTOCOL_ADDRESS, parseUnits("1000", 6)] // Approve large amount 6}); 7 8await bondWallet.sendUserOperation({ 9 to: USDC_TOKEN_ADDRESS, 10 data: approveData 11});
Problem: Intent taking too long to execute.
Solution:
1// Monitor intent status 2async function monitorIntent(userOpHash: string) { 3 const MAX_WAIT_TIME = 5 * 60 * 1000; // 5 minutes 4 const start = Date.now(); 5 6 while (Date.now() - start < MAX_WAIT_TIME) { 7 // Check if intent has been executed 8 // Implementation depends on your monitoring setup 9 10 await new Promise(resolve => setTimeout(resolve, 10000)); // Wait 10 seconds 11 } 12 13 throw new Error("Intent execution timeout"); 14}
Problem: RPC connection issues.
Solution:
1// Use multiple RPC endpoints 2const walletClient = createWalletClient({ 3 account, 4 chain: { 5 ...sepolia, 6 rpcUrls: { 7 default: { 8 http: [ 9 'https://sepolia.infura.io/v3/YOUR_KEY', 10 'https://sepolia.alchemy.com/v2/YOUR_KEY', 11 'https://rpc.sepolia.org' 12 ] 13 } 14 } 15 }, 16 transport: http() 17});
Enable debug logging:
1// Set environment variable 2process.env.BOND_DEBUG = "true"; 3 4// Or enable programmatically 5BondWallet.setDebugMode(true);
bond-protocol
1// v1.x (deprecated) 2const balance = await bondWallet.getBalance("USDC"); 3 4// v2.x (current) 5const balance = await bondWallet.unifiedBalance("USDC");
getBalance()
→ unifiedBalance()
bigint
instead of string
We welcome contributions to the Bond Wallet SDK!
1git clone https://github.com/bond-protocol/bond-wallet-js 2cd bond-wallet-js 3npm install 4npm run build 5npm test
1# Unit tests 2npm run test:unit 3 4# Integration tests (requires testnet funds) 5npm run test:integration 6 7# All tests 8npm test
MIT License - see LICENSE file for details.
getBalance()
to unifiedBalance()
Bond Wallet SDK - Simplifying Cross-Chain Development
No vulnerabilities found.
No security vulnerabilities found.