Files
xo-stack/examples/node/storageTest.js

49 lines
1.0 KiB
JavaScript

import { BlockchainElectrum, StorageMemory, WalletHD } from '@xo/wallet';
const ELECTRUM_SERVERS = [
'bch.imaginary.cash',
'cashnode.bch.ninja',
'electrum.imaginary.cash',
];
const blockchainElectrum = new BlockchainElectrum(ELECTRUM_SERVERS);
await blockchainElectrum.start();
const storage = new StorageMemory();
const walletStore = await storage.getChild('wallets');
const walletOneStore = await walletStore.getChild('1');
console.log(walletOneStore);
const cache = new StorageMemory();
const services = {
blockchain: blockchainElectrum,
storage: walletOneStore,
cache: cache,
};
const wallet = await WalletHD.from(
{
mnemonic:
'grape amazing region hand script truck veteran tilt gaze rough despair guard',
},
blockchain,
walletOneStore,
cache,
);
await wallet.start();
console.log(await storage.export());
const txs = await wallet.fetchTransactions();
console.log(txs);
const wallet2 = await WalletHD.fromStorage(services);
await wallet2.start();
console.log(await wallet2.fetchTransactions());