Storage adapters provide persistent storage for wallet data across different platforms. For production use, always configure a persistent adapter rather than the default in-memory store.
Overview
By default, the Arkade SDK uses InMemoryStorageAdapter which stores data in memory and loses it when the application restarts. For production applications, you should use a persistent storage adapter appropriate for your environment.
Available Storage Adapters
LocalStorage Browser/PWA persistent storage using localStorage API
IndexedDB Browser/PWA/Service Worker advanced storage with IndexedDB
AsyncStorage React Native persistent storage
FileSystem Node.js file-based storage
Storage Adapter Interface
All storage adapters implement the same interface:
interface StorageAdapter {
getItem ( key : string ) : Promise < string | null >
setItem ( key : string , value : string ) : Promise < void >
removeItem ( key : string ) : Promise < void >
clear () : Promise < void >
}
Browser LocalStorage
For browser applications, use LocalStorageAdapter for simple persistent storage:
import { Wallet , MnemonicIdentity } from '@arkade-os/sdk'
import { LocalStorageAdapter } from '@arkade-os/sdk/adapters/localStorage'
import { generateMnemonic } from '@scure/bip39'
import { wordlist } from '@scure/bip39/wordlists/english'
const storage = new LocalStorageAdapter ()
// Load or create identity
let mnemonic = await storage . getItem ( 'mnemonic' )
if ( ! mnemonic ) {
mnemonic = generateMnemonic ( wordlist )
await storage . setItem ( 'mnemonic' , mnemonic )
}
const identity = MnemonicIdentity . fromMnemonic ( mnemonic )
const wallet = await Wallet . create ({
identity ,
arkServerUrl: 'https://arkade.computer' ,
storage
})
Browser IndexedDB
For more advanced browser applications or service workers, use IndexedDBStorageAdapter:
import { Wallet , MnemonicIdentity } from '@arkade-os/sdk'
import { IndexedDBStorageAdapter } from '@arkade-os/sdk/adapters/indexedDB'
const storage = new IndexedDBStorageAdapter ( 'my-app' , 1 )
// Load identity from storage
const mnemonic = await storage . getItem ( 'mnemonic' )
const identity = MnemonicIdentity . fromMnemonic ( mnemonic )
const wallet = await Wallet . create ({
identity ,
arkServerUrl: 'https://arkade.computer' ,
storage
})
IndexedDB is recommended for service workers and applications that need to store large amounts of data.
React Native AsyncStorage
For React Native applications, use AsyncStorageAdapter:
import { Wallet , MnemonicIdentity } from '@arkade-os/sdk'
import { AsyncStorageAdapter } from '@arkade-os/sdk/adapters/asyncStorage'
const storage = new AsyncStorageAdapter ()
// Load identity from storage
const mnemonic = await storage . getItem ( 'mnemonic' )
const identity = MnemonicIdentity . fromMnemonic ( mnemonic )
const wallet = await Wallet . create ({
identity ,
arkServerUrl: 'https://arkade.computer' ,
storage
})
Node.js FileSystem
For Node.js applications, use FileSystemStorageAdapter:
import { Wallet , MnemonicIdentity } from '@arkade-os/sdk'
import { FileSystemStorageAdapter } from '@arkade-os/sdk/adapters/fileSystem'
const storage = new FileSystemStorageAdapter ( './wallet-data' )
// Load identity from storage
const mnemonic = await storage . getItem ( 'mnemonic' )
const identity = MnemonicIdentity . fromMnemonic ( mnemonic )
const wallet = await Wallet . create ({
identity ,
arkServerUrl: 'https://arkade.computer' ,
storage
})
Example: Identity Management
Here’s a complete example showing how to manage identity across sessions:
import { Wallet , MnemonicIdentity } from '@arkade-os/sdk'
import { LocalStorageAdapter } from '@arkade-os/sdk/adapters/localStorage'
import { generateMnemonic } from '@scure/bip39'
import { wordlist } from '@scure/bip39/wordlists/english'
const storage = new LocalStorageAdapter ()
// Try to load existing identity
let mnemonic = await storage . getItem ( 'mnemonic' )
if ( ! mnemonic ) {
// Create new identity
console . log ( 'Creating new wallet identity...' )
mnemonic = generateMnemonic ( wordlist )
// Save to storage
await storage . setItem ( 'mnemonic' , mnemonic )
console . log ( 'New identity saved to storage' )
} else {
console . log ( 'Loaded existing identity from storage' )
}
const identity = MnemonicIdentity . fromMnemonic ( mnemonic )
// Create wallet with persistent storage
const wallet = await Wallet . create ({
identity ,
arkServerUrl: 'https://arkade.computer' ,
storage
})
const address = await wallet . getAddress ()
console . log ( 'Wallet address:' , address )
Repository Pattern
The SDK also exposes repositories for low-level data management:
// VTXO management (automatically cached for performance)
const addr = await wallet . getAddress ()
const vtxos = await wallet . walletRepository . getVtxos ( addr )
await wallet . walletRepository . saveVtxos ( addr , vtxos )
// Contract data for SDK integrations
await wallet . contractRepository . setContractData ( 'my-contract' , 'status' , 'active' )
const status = await wallet . contractRepository . getContractData ( 'my-contract' , 'status' )
// Collection management for related data
await wallet . contractRepository . saveToContractCollection (
'swaps' ,
{ id: 'swap-1' , amount: 50000 , type: 'reverse' },
'id' // key field
)
const swaps = await wallet . contractRepository . getContractCollection ( 'swaps' )
Next Steps