githubEdit

Error Handling

Learn about common errors and best practices.

This guide covers recommended patterns for error handling and security when using the WDK.

Handling Common Errors

When interacting with multiple chains and protocols, various runtime issues may occur.

Missing Registration

The most common error is attempting to access a wallet or protocol that hasn't been registered.

Check Registration Pattern
try {
  // This will throw if 'tron' was never registered via .registerWallet()
  const tronAccount = await wdk.getAccount('tron', 0)
} catch (error) {
  console.error('Tron wallet not available:', error.message)
}
circle-info

Always use try/catch blocks when initializing sessions or accessing dynamic features.

Memory Management

For security, you should clear sensitive data from memory when a session is complete. The WDK provides a .dispose() method for this purpose.

Disposing the Instance

Calling dispose() clears the seed phrase and private keys derived in memory.

circle-exclamation

Security Best Practices

Environment Variables

Never hardcode API keys or seed phrases in your source code. Use environment variables (e.g., process.env.TON_API_KEY).

Secure Storage

If you persist a session, never store the raw seed phrase in local storage. Use secure operating system storage (like Keychain on macOS or Keystore on Android).