npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

monero-rpc

v0.5.0

Published

> node wrapper for monero daemon and wallet rpc

Downloads

130

Readme

node-monero-rpc

node wrapper for monero daemon and wallet rpc

Table of Contents

Installation

npm install --save monero-rpc

Documentation

Daemon API

Initialisation

Instantiate a new Daemon object:

const Daemon = require('monero-rpc').Daemon

const daemon = new Daemon('http://localhost:18081')
const daemon = new Daemon('http://node.monero.hashvault.pro:18081') // or use a remote node
Methods
getLastBlockHeight(callback)

Look up how many blocks are in the longest chain known to the node.

daemon.getLastBlockHeight((err, height) => {
    if (err) return console.log(err)
    console.log(height) // 993163
})
getLastBlockHeader(callback)

Look up how many blocks are in the longest chain known to the node.

daemon.getLastBlockHeader((err, header) => {
    if (err) return console.log(err)
    console.log(header)
    /*
     * {
     *     "depth": 0,
     *     "difficulty": 746963928,
     *     "hash": "ac0f1e2262...",
     *     "height": 990793,
     *     "major_version": 1,
     *     "minor_version": 1,
     *     "nonce": 1550,
     *     "orphan_status": false,
     *     "prev_hash": "386575e3b0...",
     *     "reward": 6856609225169,
     *     "timestamp": 1457589942
     * }
     */
})
getBlockHeader(id, callback)

Block header information can be retrieved using either a block's hash or height.

By height:

daemon.getBlockHeader(990793, (err, header) => {
    if (err) return console.log(err)
    console.log(header)
    /*
     * {
     *     "depth": 0,
     *     "difficulty": 746963928,
     *     "hash": "ac0f1e2262...",
     *     "height": 990793,
     *     "major_version": 1,
     *     "minor_version": 1,
     *     "nonce": 1550,
     *     "orphan_status": false,
     *     "prev_hash": "386575e3b0...",
     *     "reward": 6856609225169,
     *     "timestamp": 1457589942
     * }
     */
})

By hash:

daemon.getBlockHeader('ac0f1e2262...', (err, header) => {
    if (err) return console.log(err)
    console.log(header)
    /*
     * {
     *     "depth": 0,
     *     "difficulty": 746963928,
     *     "hash": "ac0f1e2262...",
     *     "height": 990793,
     *     "major_version": 1,
     *     "minor_version": 1,
     *     "nonce": 1550,
     *     "orphan_status": false,
     *     "prev_hash": "386575e3b0...",
     *     "reward": 6856609225169,
     *     "timestamp": 1457589942
     * }
     */
})
getBlock(id, callback)

Full block information can be retrieved by either block height or hash, like with the block header calls.

daemon.getBlock('ac0f1e2262...', (err, block) => {
    if (err) return console.log(err)
    console.log(block) // { ... }
})
getBlockTemplate(address, reserved, callback)

Get a new block template for mining.

daemon.getBlockTemplate('46tFLJPaNyy...', 17, (err, template) => {
    if (err) return console.log(err)
    console.log(template) // { ... }
})
submitBlock(blob, callback)

Submit a block to the network.

daemon.submitBlock('...', (err) => {
    if (err) return console.log(err)
    console.log('hurray') // 'hurray'
})
getKeyImagesSpent(keyImages, callback)

Check if a key image is spent.

daemon.getKeyImagesSpent(['8d1bd818...', '7319134bf...'], (err, status) => {
    if (err) return console.log(err)
    console.log(status) // [1, 1]
})
stop(callback)
daemon.stop((err) => {
    if (err) return console.log(err)
    console.log(':(') // ':('
})
getInfo(callback)

Get miscellaneous information about the state of this daemon and the network.

daemon.getInfo((err, info) => {
    if (err) return console.log(err)
    console.log(info)
    /*
     * {
     *     "alt_blocks_count": 5,
     *     "difficulty": 972165250,
     *     "grey_peerlist_size": 2280,
     *     "height": 993145,
     *     "incoming_connections_count": 0,
     *     "outgoing_connections_count": 8,
     *     "status": "OK",
     *     "target": 60,
     *     "target_height": 993137,
     *     "testnet": false,
     *     "top_block_hash": "",
     *     "tx_count": 564287,
     *     "tx_pool_size": 45,
     *     "white_peerlist_size": 529
     * }
     */
})
isTestnet(callback)

Get miscellaneous information about the state of this daemon and the network.

daemon.isTestnet((err, testnet) => {
    if (err) return console.log(err)
    console.log(testnet) // false
})

Wallet API

Warning

All amounts are in atomic units. 1 Monero is 1e12 atomic units.

Initialisation

Start monero-wallet-rpc:

monero-wallet-rpc --wallet-file mywallet --rpc-bind-port 18082 --disable-rpc-login

Instantiate a new Wallet object:

const Wallet = require('monero-rpc').Wallet
const wallet = new Wallet('http://localhost:18082')
Methods
getAddress(callback)

Get the wallet's address.

wallet.getAddress((err, address) => {
    if (err) return console.log(err)
    console.log(address) // '46tFLJPaNyy...'
})
getBalance(callback)

Get the wallet's balance.

wallet.getBalance((err, balance) => {
    if (err) return console.log(err)
    console.log(balance.total) // 140000000000
    console.log(balance.unlocked) // 50000000000
})
transfer(options, callback)

Send Monero.

wallet.transfer({
    destinations: [
        { address: '48vegnn...', amount: 10000000 }
    ],
    mixin: 7, // default 7
    priority: 0 // default 0
}, (err, result) => {
    if (err) return console.log(err)
    console.log(result.fee) // 48958481211
    console.log(result.tx_hash) // '985180f46863...'
})
splitTransfer(options, callback)

Send monero, and split into multiple transactions if required.

wallet.splitTransfer({
    destinations: [
        { address: '48vegnn...', amount: 10000000 }
    ],
    mixin: 7, // default 7
    priority: 0 // default 0
}, (err, result) => {
    if (err) return console.log(err)
    console.log(result)
    /*
     * {
     *     "fee_list": [48958481211],
     *     "tx_hash_list": ['985180f46863...']
     * }
     */
})
getPayments(paymentId, callback)

Get a list of incoming payments using a given payment id.

wallet.getPayments('4279257e...', (err, payments) => {
    if (err) return console.log(err)
    console.log(payments)
    /*
     * [
     *     {
     *         "amount": 10350000000000,
     *         "block_height": 994327,
     *         "payment_id": "4279257e0a2...",
     *         "tx_hash": "c391089f5b1b02...",
     *         "unlock_time": 0
     *     }
     * ]
     */
})
getRandomIntegratedAddress(callback)

Generate a random integrated address.

wallet.getRandomIntegratedAddress((err, result) => {
    if (err) return console.log(err)
    console.log(result.paymentId) // 'f89f4978b6304b7b'
    console.log(result.address) // '46tFLJPaNyy...'
})
getBulkPayments(paymentIds, height, callback)

Get a list of payments using a list of payment ids from a given height.

wallet.getBulkPayments(['4279257e0a2...'], 990000, (err, result) => {
    if (err) return console.log(err)
    console.log(result)
    /*
     * [
     *     {
     *         "amount": 10350000000000,
     *         "block_height": 994327,
     *         "payment_id": "4279257e0a2...",
     *         "tx_hash": "c391089f5b1...",
     *         "unlock_time": 0
     *     }
     * ]
     */
})

Testing

Code is linted with eslint and tested with Jest. Run npm test to lint and run test suite.

Warning

This library is not complete. This library probably has bugs. ~~This library eats babies.~~ Don't use it unless you know what you're getting yourself into. See the GitHub issues for a list of features which are missing.

Projects using node-monero-rpc

Feel free to create a pull request to add your own project.

License

Released under the 3-Clause BSD License. See LICENSE for more information.