diff --git a/README.md b/README.md index b4868d1..3d409c3 100644 --- a/README.md +++ b/README.md @@ -4,18 +4,40 @@ Simple wrapper for monero-wallet-rpc calls. ```javascript import Wallet from 'monero-wallet-rpc-js' +(async () => { -// Create a new walletRpc connection -const wallet = new Wallet({ - url: 'http://localhost:18082', - filename: 'mywallet', - password: 'secretpassword', - address: '4....', - viewKey: 'XXXXXXX....', - restoreHeight: '573936', -}) + // Load wallet + let wallet; try { + wallet = new Wallet({ + url: 'http://localhost:18082', + filename: 'mywallet', + password: 'secretpassword', + address: '4....', + viewKey: 'XXXXXXX...', + spendKey: 'XXXXXXX...', + restoreHeight: '573936', + }) + } catch (err) { + console.error(`Failed to open wallet: ${err}`) + } -// Call it -let height = await wallet.rpc('get_height') -console.log(`Synced height: ${height}`) + // Save wallet + await wallet.store() + + // Auto-save wallet + const AUTOSAVE_SEC = 10 + setInterval(await wallet.store(), AUTOSAVE_SEC) + + // Wrapped methods + console.log(await wallet.getHeight()) // 3132418 + // Some return objects + // See https://www.getmonero.org/resources/developer-guides/wallet-rpc.html#get_balance + let bal = await wallet.getBalance() + console.log(`Balance: ${bal.balance} + Unlocked: ${bal.unlocked_balance}`) + + // Arbitrary RPC call + console.log((await wallet.rpc('get_address', { + account_index: 2 + })).address) ```