docs: 📝 Improved docs
parent
3f2c60b00d
commit
ba9985ad2f
46
README.md
46
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)
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue