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 ```javascript
import Wallet from 'monero-wallet-rpc-js' import Wallet from 'monero-wallet-rpc-js'
(async () => {
// Create a new walletRpc connection // Load wallet
const wallet = new Wallet({ let wallet; try {
url: 'http://localhost:18082', wallet = new Wallet({
filename: 'mywallet', url: 'http://localhost:18082',
password: 'secretpassword', filename: 'mywallet',
address: '4....', password: 'secretpassword',
viewKey: 'XXXXXXX....', address: '4....',
restoreHeight: '573936', viewKey: 'XXXXXXX...',
}) spendKey: 'XXXXXXX...',
restoreHeight: '573936',
})
} catch (err) {
console.error(`Failed to open wallet: ${err}`)
}
// Call it // Save wallet
let height = await wallet.rpc('get_height') await wallet.store()
console.log(`Synced height: ${height}`)
// 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)
``` ```