@@ -707,25 +707,69 @@ class MyWalletRepository implements WalletRepository {
707707}
708708```
709709
710- Note: ` IndexedDB*Repository ` requires [ indexeddbshim] ( https://github.com/indexeddbshim/indexeddbshim ) in Node or other
711- ** non-browser environments** . It is a dev dependency of the SDK, so you must
712- install and initialize it in your app before using the repositories. This
713- also applies when you rely on the default storage behavior (no ` storage ` ).
710+ #### SQLite Repository (Node.js / React Native)
714711
715- Please see the working example in [ examples/node/multiple-wallets.ts] ( examples/node/multiple-wallets.ts ) .
712+ For Node.js or React Native environments, use the SQLite repository with any
713+ SQLite driver. The SDK accepts a ` SQLExecutor ` interface — you provide the
714+ driver, the SDK handles the schema.
715+
716+ See [ examples/node/multiple-wallets.ts] ( examples/node/multiple-wallets.ts ) for
717+ a full working example using ` better-sqlite3 ` .
716718
717719``` typescript
718720import { SingleKey , Wallet } from ' @arkade-os/sdk'
719- import setGlobalVars from ' indexeddbshim'
721+ import { SQLiteWalletRepository , SQLiteContractRepository , SQLExecutor } from ' @arkade-os/sdk/repositories/sqlite'
722+ import Database from ' better-sqlite3'
720723
721- setGlobalVars ()
724+ const db = new Database (' my-wallet.sqlite' )
725+ db .pragma (' journal_mode = WAL' )
722726
723- const identity = SingleKey .fromHex (' your_private_key_hex' )
727+ const executor: SQLExecutor = {
728+ run : async (sql , params ) => { db .prepare (sql ).run (... (params ?? [])) },
729+ get : async (sql , params ) => db .prepare (sql ).get (... (params ?? [])) as any ,
730+ all : async (sql , params ) => db .prepare (sql ).all (... (params ?? [])) as any ,
731+ }
724732
725- // Create wallet with default IndexedDB storage
733+ const wallet = await Wallet .create ({
734+ identity: SingleKey .fromHex (' your_private_key_hex' ),
735+ arkServerUrl: ' https://mutinynet.arkade.sh' ,
736+ storage: {
737+ walletRepository: new SQLiteWalletRepository (executor ),
738+ contractRepository: new SQLiteContractRepository (executor ),
739+ },
740+ })
741+ ```
742+
743+ #### Realm Repository (React Native)
744+
745+ For React Native apps using Realm, pass your Realm instance directly:
746+
747+ ``` typescript
748+ import { RealmWalletRepository , RealmContractRepository , ArkRealmSchemas } from ' @arkade-os/sdk/repositories/realm'
749+
750+ const realm = await Realm .open ({ schema: [... ArkRealmSchemas , ... yourSchemas ] })
726751const wallet = await Wallet .create ({
727752 identity ,
728753 arkServerUrl: ' https://mutinynet.arkade.sh' ,
754+ storage: {
755+ walletRepository: new RealmWalletRepository (realm ),
756+ contractRepository: new RealmContractRepository (realm ),
757+ },
758+ })
759+ ```
760+
761+ #### IndexedDB Repository (Browser)
762+
763+ In the browser, the SDK defaults to IndexedDB repositories when no ` storage `
764+ is provided:
765+
766+ ``` typescript
767+ import { SingleKey , Wallet } from ' @arkade-os/sdk'
768+
769+ const wallet = await Wallet .create ({
770+ identity: SingleKey .fromHex (' your_private_key_hex' ),
771+ arkServerUrl: ' https://mutinynet.arkade.sh' ,
772+ // Uses IndexedDB by default in the browser
729773})
730774```
731775
@@ -813,26 +857,31 @@ Both ExpoArkProvider and ExpoIndexerProvider are available as adapters following
813857- ** ExpoArkProvider** : Handles settlement events and transaction streaming using expo/fetch for Server-Sent Events
814858- ** ExpoIndexerProvider** : Handles address subscriptions and VTXO updates using expo/fetch for JSON streaming
815859
816- To use IndexedDB repositories in Expo/React Native, call ` setupExpoDb() ` before any SDK import.
817- This sets up ` indexeddbshim ` backed by expo-sqlite under the hood:
860+ For persistence in Expo/React Native, use the SQLite repository with ` expo-sqlite ` :
818861
819862``` typescript
820- import { setupExpoDb } from ' @arkade-os/sdk/adapters/expo-db' ;
863+ import { SQLiteWalletRepository , SQLiteContractRepository } from ' @arkade-os/sdk/repositories/sqlite'
864+ import * as SQLite from ' expo-sqlite'
865+
866+ const db = SQLite .openDatabaseSync (' my-wallet.db' )
867+ const executor = {
868+ run : (sql , params ) => db .runAsync (sql , params ?? []),
869+ get : (sql , params ) => db .getFirstAsync (sql , params ?? []),
870+ all : (sql , params ) => db .getAllAsync (sql , params ?? []),
871+ }
821872
822- setupExpoDb ();
873+ const wallet = await Wallet .create ({
874+ identity ,
875+ arkServerUrl: ' https://mutinynet.arkade.sh' ,
876+ arkProvider: new ExpoArkProvider (' https://mutinynet.arkade.sh' ),
877+ indexerProvider: new ExpoIndexerProvider (' https://mutinynet.arkade.sh' ),
878+ storage: {
879+ walletRepository: new SQLiteWalletRepository (executor ),
880+ contractRepository: new SQLiteContractRepository (executor ),
881+ },
882+ })
823883```
824884
825- > ** Note:** ` setupExpoDb ` accepts an optional ` SetupExpoDbOptions ` object to
826- > customise ` origin ` , ` checkOrigin ` , and ` cacheDatabaseInstances ` .
827-
828- > ** Note:** ` expo-sqlite ` and ` indexeddbshim ` are optional peer dependencies,
829- > only required when importing from ` @arkade-os/sdk/adapters/expo-db ` . The
830- > streaming providers (` @arkade-os/sdk/adapters/expo ` ) have no expo-sqlite
831- > dependency. Install them with:
832- > ``` bash
833- > npx expo install expo-sqlite && npm install indexeddbshim
834- > ` ` `
835-
836885#### Crypto Polyfill Requirement
837886
838887Install ` expo-crypto ` and polyfill ` crypto.getRandomValues() ` at the top of your app entry point:
0 commit comments