50 lines
1.1 KiB
Markdown
50 lines
1.1 KiB
Markdown
# monero-wallet-rpc-js
|
|
|
|
Simple wrapper for monero-wallet-rpc calls.
|
|
|
|
```javascript
|
|
import Wallet from 'monero-wallet-rpc-js'
|
|
|
|
// Load wallet
|
|
let loadedWallet; try {
|
|
loadedWallet = await 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}`)
|
|
}
|
|
|
|
(async (wallet) => {
|
|
|
|
// 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)
|
|
|
|
// Save and close wallet
|
|
await wallet.close()
|
|
|
|
})(loadedWallet)
|
|
```
|