docs: 📝 Improved docs

main
Keith Irwin 2024-04-21 13:44:11 -06:00
parent 3f2c60b00d
commit ba9985ad2f
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
1 changed files with 34 additions and 12 deletions

View File

@ -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)
```