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
|
```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)
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue