monero-wallet-rpc-js

1.2.22 • Public • Published

monero-wallet-rpc-js

Simple wrapper for monero-wallet-rpc calls.

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...',
		restore_height: '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)

Readme

Keywords

none

Package Sidebar

Install

npm i monero-wallet-rpc-js

Weekly Downloads

0

Version

1.2.22

License

MIT

Unpacked Size

4.3 kB

Total Files

3

Last publish

Collaborators

  • keith24