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

@mymonero/mymonero-lws-client

v3.0.0

Published

Connector for using a Monero compliant light wallet api

Downloads

585

Readme

:warning: This project is under heavy development. Expect bugs & breaking changes.


Usage

Installation

npm i @mymonero/mymonero-lws-client

Initialize

Initialize the Light Wallet Client.

const axios = require('axios').default
const LWSClient = require('@mymonero/mymonero-lws-client')
const options = {
    httpClient: axios,
    url: 'https://api.mymonero.com',
    appName: 'MyMonero',
    appVersion: '1.1.25',
    apiKey: '<insert your api key here>' // can be null for certain queries
}
const lwsClient = new LWSClient(options)

Login

Confirms if the the account is on the MyMonero servers. if the create parameter is true it will add the wallet to the MyMonero servers.

const privateViewKey = '7bea1907940afdd480eff7c4bcadb478a0fbb626df9e3ed74ae801e18f53e104'
const address = '43zxvpcj5Xv9SEkNXbMCG7LPQStHMpFCQCmkmR4u5nzjWwq5Xkv5VmGgYEsHXg4ja2FGRD5wMWbBVMijDTqmmVqm93wHGkg'
const addAccount = true
const result = await lwsClient.login(
  privateViewKey,
  address,
  true
)
console.log(result)

Example Response

{
    "new_address": true,
    "start_height": 0
}

Get Addresses Transactions

Fetches all the transactions associated with the address. This includes decoys. The decoys can be removed by using the generateKeyImage function in the mymonero-client repo.

const privateViewKey = '7bea1907940afdd480eff7c4bcadb478a0fbb626df9e3ed74ae801e18f53e104'
const address = '43zxvpcj5Xv9SEkNXbMCG7LPQStHMpFCQCmkmR4u5nzjWwq5Xkv5VmGgYEsHXg4ja2FGRD5wMWbBVMijDTqmmVqm93wHGkg'
const result = await lwsClient.getAddressTxs(
  privateViewKey,
  address
)
console.log(result)

Example Response

{
    "transactions": [
        {
            "hash": "db58a141d1f29e0c9c43ab4016805a214386591b1699f1b16f56d330e59abf6a",
            "id": 17862204,
            "timestamp": "2021-08-03T10:27:35Z",
            "total_received": "10000000000",
            "total_sent": "0",
            "unlock_time": 0,
            "height": 2418938,
            "coinbase": false,
            "mempool": false,
            "mixin": 10
        },
        {
            "hash": "5486052ec89d85a597379ac843be59c1e0f3f67bec996c97a13de2d5b0a468fc",
            "id": 17868342,
            "timestamp": "2021-08-03T14:55:09Z",
            "total_received": "0",
            "total_sent": "10000000000",
            "fee": "43483770000",
            "unlock_time": 0,
            "height": 2419038,
            "coinbase": false,
            "mempool": false,
            "mixin": 10,
            "spent_outputs": [
                {
                    "tx_pub_key": "585d3601bc6f3b63ad041fbb5f301a6239cbc98ec2954ef827d5f81aed59cff9",
                    "key_image": "d77a7e53417a11110138290dd6be8df3709d4815016eda88fcd2722dfd083666",
                    "amount": "10000000000",
                    "out_index": 1,
                    "mixin": 10
                }
            ]
        }
    ],
    "total_received": "10000000000",
    "scanned_height": 18301331,
    "scanned_block_height": 2429062,
    "start_height": 0,
    "transaction_height": 18324649,
    "blockchain_height": 2429625
}

Fetch Addresses Unspent Outputs

Fetches all outputs available. They will need to be key imaged to work out which have been spent.

This function also returns the fee per byte and fee mask for calculating the transaction fees.

Requires an API key to be set when initialising lwsClient

const privateViewKey = '7bea1907940afdd480eff7c4bcadb478a0fbb626df9e3ed74ae801e18f53e104'
const address = '43zxvpcj5Xv9SEkNXbMCG7LPQStHMpFCQCmkmR4u5nzjWwq5Xkv5VmGgYEsHXg4ja2FGRD5wMWbBVMijDTqmmVqm93wHGkg'
const result = await lwsClient.unspentOutputs(
  privateViewKey,
  address
)
console.log(result)

Example Response

{
    "amount": "10000000000",
    "outputs": [
        {
            "amount": "10000000000",
            "public_key": "b155970fc6ba59a45292e2441dba05c1f7a9c5b7a9bf2b740ad506ebca63d849",
            "index": 1,
            "global_index": 36462743,
            "rct": "da0d240d02bc9cbbcfaf86b216248f7828b5a03ba67e594e67a75b925a67a57b75b111ee6ac33d99",
            "tx_id": 17862204,
            "tx_hash": "db58a141d1f29e0c9c43ab4016805a214386591b1699f1b16f56d330e59abf6a",
            "tx_pub_key": "585d3601bc6f3b63ad041fbb5f301a6239cbc98ec2954ef827d5f81aed59cff9",
            "tx_prefix_hash": "c737a8b9de9c26854ff1753a70e9adad629dbdb4c2ff3c5bde37b566479b09f5",
            "spend_key_images": [
                "d77a7e53417a11110138290dd6be8df3709d4815016eda88fcd2722dfd083666",
                "8602033b812d0586b34cf4fb430c01360d313d64faab8ce4a0414434ea5c213c",
                "cbbad7da43d5ff9c51e3bc2c60c53abfad9d7d32acff8d352f8e3f58c19032f4",
                "d7df16cecab36d74ade484ec08506cba8cc0b1d3e1e7d3f3fd2994b60f2eb0ee",
                "62d2a17a7166a353c0246e18c741831ad108c40fc5b2582a2aeb04fd78f9e25d"
            ],
            "height": 2418938,
            "timestamp": "2021-08-18T06:22:09Z"
        }
    ],
    "per_byte_fee": 5993,
    "fee_mask": 10000,
    "fork_version": 14
}

Fetches decoy mixin outputs

Fetches decoys for the number of required outputs.

const numberOfOutputs = 2
const result = await lwsClient.randomOutputs(numberOfOutputs)
console.log(result)

Example Response

{
    "amount_outs": [
        {
            "amount": "0",
            "outputs": [
                {
                    "global_index": "36366289",
                    "public_key": "6965bee02aa3ff532defc5c8606091a95ab3afffea59a2678e3a922eea7fc479",
                    "rct": "b6371b3c730e7b5f0a1420c5d1922c9b9201c39421a33aece82d5ba4e994c698"
                },
                {
                    "global_index": "37519665",
                    "public_key": "e8504b73dca7fe73307183e32f443b8a5f3b7730799c6aa11b58ff37bcb8e623",
                    "rct": "1e02dbfc896c7ed218d954178d190641a2e73b212b22e249d9267b50c8933390"
                },
                {
                    "global_index": "37520147",
                    "public_key": "72506b0134fbdc644bc1a4e9270d192f56e3a3b888168b056ddfbc1863545ddc",
                    "rct": "f41031231b821487eda43533b97df15b634a73af233867e685d03f51408b9656"
                }
            ]
        }
    ]
}

Submit Transaction

Sends the Raw transaction to the server to broadcast to the network.

const tx = '02000102000bc7a1c704e.............343359c302e5'
const result = await lwsClient.submitRawTx(tx)
console.log(result)

Exchange Rates

Fetches the latest exchange rates from the server.

const result = await lwsClient.exchangeRates()
console.log(result)

Example Response

{
    "AUD": 353.3,
    "BRL": 1375.62,
    "BTC": 0.005675,
    "CAD": 323.61,
    "CHF": 234.96,
    "CNY": 1619.55,
    "EUR": 219.79,
    "GBP": 186.63,
    "HKD": 2002.7,
    "INR": 21752.24,
    "JPY": 28130.07,
    "KRW": 302286.12,
    "MXN": 5171.11,
    "NOK": 2031.77,
    "NZD": 371.74,
    "SEK": 2591.29,
    "SGD": 349.33,
    "TRY": 2196.06,
    "USD": 257.44,
    "RUB": 18453.98,
    "ZAR": 3947.61
}

Get Address info

Should no longer be used. Returns almost all the same info as the getAddressTxs call but included the exchange rates. The exchange rates can now be called via exchangeRates API call.

const privateViewKey = '7bea1907940afdd480eff7c4bcadb478a0fbb626df9e3ed74ae801e18f53e104'
const address = '43zxvpcj5Xv9SEkNXbMCG7LPQStHMpFCQCmkmR4u5nzjWwq5Xkv5VmGgYEsHXg4ja2FGRD5wMWbBVMijDTqmmVqm93wHGkg'
const result = await lwsClient.getAddressInfo(
  privateViewKey,
  address
)
console.log(result)

Import Wallet

Submits request to import wallet information. One of the following options: start_block_height, start_date, or start_tx_height must be specified.

Requires an API key to be set when initialising lwsClient

const view_key = '7bea1907940afdd480eff7c4bcadb478a0fbb626df9e3ed74ae801e18f53e104'
const address = '43zxvpcj5Xv9SEkNXbMCG7LPQStHMpFCQCmkmR4u5nzjWwq5Xkv5VmGgYEsHXg4ja2FGRD5wMWbBVMijDTqmmVqm93wHGkg'
const start_block_height = 0 
const result = await lwsClient.import_wallet_auth(
    address,
    view_key, 
    start_block_height,
    start_tx_height = null
    start_date = null
)
console.log(result)

Resync wallet

Syncs wallet from block 0.

Requires an API key to be set when initialising lwsClient

const address = '43zxvpcj5Xv9SEkNXbMCG7LPQStHMpFCQCmkmR4u5nzjWwq5Xkv5VmGgYEsHXg4ja2FGRD5wMWbBVMijDTqmmVqm93wHGkg'
const result = await lwsClient.import_wallet_auth(
    address,
    view_key, 
    start_block_height,
    start_tx_height = null
    start_date = null
)
console.log(result)

License

See LICENSE.txt for license.

All source code copyright © 2021 by MyMonero. All rights reserved.