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

@logosnetwork/logos-rpc-client

v1.1.33

Published

Promise-based client for interacting and building services on top of the Logos network.

Downloads

71

Readme

Promise-based client for interacting and building services on top of the Logos network

Install

npm i @logosnetwork/logos-rpc-client

Your own Logos Node

To setup a direct connection to a Logos node do the following

const LogosRPC = require('@logosnetwork/logos-rpc-client')
const logos = new LogosRPC({url: 'http://3.215.28.211:55000'})

You may also proxy your RPC calls through another server

const LogosRPC = require('@logosnetwork/logos-rpc-client')
const logos = new LogosRPC({url: 'http://3.215.28.211:55000', proxyURL: 'https://pla.bs'})

To setup a proxy server include something similar to the following in your server

app.post('/rpc', async (req, res) => {
  let targetURL = req.body.targetURL
  delete req.body.targetURL
  const response = await axios.post(`${targetURL}/`, req.body)
  res.send(response.data)
})

Remote Logos Node

Simply follow the same steps are seen above and use one of the current delegates found here: delegate list sorted by their delegate id.

Delegate Load Balancing

When building for production you must select the proper delegate for publishing your transactions. If you do not select the proper delegate you will incur a 5 second transaction confirmation penalty. This is an incentive to load balance the requests to the 32 delegates equally.

Here is an example of how to calculate the proper delegate id given an ACCOUNT_ID.

let delegateID = null

//Check the most recent 
//on the account who wants to publish
if (accountFrontier === '0000000000000000000000000000000000000000000000000000000000000000') {
    // If the frontier doesn't exist We use the 
    // last two digits of the hexadecimal hash 
    // of the public key mod 32 to give us a 
    // random distribution
    delegateID = parseInt(publicKey.slice(-2), 16) % 32
} else {
    // When the account has a previous transaction 
    // we use the last two digits of the hexadecimal hash
    // mod 32 to give us a random distribution
    delegateID = parseInt(accountFrontier.slice(-2), 16) % 32
}

Once you have the delegate id you can find the delegate from the delegate list here.

logos.changeServer(`http://${delegateList[delegateId]}:55000`)

Debug mode

To enable some helpful logs, pass debug: true as a paramater in the constructor object.

Working with accounts

Generate an account

It's easy to generate a new random account. You'll get the account's private and public keys along with its address.

const {privateKey, publicKey, address} = await logos.key.create()

Send funds

await logos.account(PRIVATE_KEY).send(0.01, RECIPIENT_ADDRESS)

Full list of methods

All methods return native or Bluebird promises and are fully compatible with async/await.

Accounts

Account methods take a single account string or in some cases, an array of accounts.

  • logos.accounts.toAddress(publicKey: string)
  • logos.accounts.reasonBalance(account: string)
  • logos.accounts.logosBalance(account: string)
  • logos.accounts.balances(accounts: string[])
  • logos.accounts.blockCount(account: string)
  • logos.accounts.history(account: string, count?: number)
  • logos.accounts.info(account: string)

Keys

Used for generating accounts and extrapolating public keys/addresses from private keys.

  • logos.key.create()
  • logos.key.expand(privateKey: string)

Transactions

Has a method to get information about transactions:

  • logos.transactions.info(hashOrHahes: string | string[], details?: boolean)

Method to construct a transaction:

  • logos.transactions.createSend(block: SendBlock)

And a method to publish a constructed block to the network:

  • logos.transactions.publish(block: string)

Request Blocks

Allows you to retrieve information on request blocks

  • logos.requestBlocks.history(count: string | number, delegateIndex: string | number, hash: string)
  • logos.requestBlocks.get(hashes: [string])

Micro Epochs

Allows you to retrieve information on micro epochs

  • logos.microEpochs.history(count: string | number, hash: string)
  • logos.microEpochs.get(hashes: [string])

Epochs

Allows you to retrieve information on epochs

  • logos.epochs.history(count: string | number, hash: string)
  • logos.epochs.get(hashes: [string])

Unit Converter

Allows you to convert LOGOS amounts to and from their reason values. Reason is the smallest unit of the Logos currency.

const LogosRPC = require('@logosnetwork/logos-rpc-client')
const logos = new LogosRPC({url: 'http://3.215.28.211:55000', proxyURL: 'https://pla.bs'})
let amountInReason = logos.convert.toReason('1', 'LOGOS')
import { convert } from '@logosnetwork/logos-rpc-client'
let amountInReason = convert.toReason('1', 'LOGOS')
let amountInLogos = convert.fromReason('1000000000000000000000000000000', 'LOGOS')
// Converter can also be used to convert token values
// or in this example bitcoin into satoshis
let bitcoinsInSatoshis = convert.fromTo('1', 8, 0)
// You can use the fromTo function for the example above also
amountInReason = convert.fromTo('1', 30, 0) // '1000000000000000000000000000000' Reason
amountInLogos = convert.fromTo('1000000000000000000000000000000', 0, 30) // '1' LOGOS
  • logos.convert.toReason(amount: string | number, denomination: 'LOGOS')
  • logos.convert.fromReason(amount: string, denomination: 'LOGOS')
  • logos.convert.fromTo(amount: string, currentDec: number, preferedDec: number)

Work

Allows you to generate and validate Proof of Work for a given block hash.

  • logos.work.generate(hash: string)
  • logos.work.validate(work: string, hash: string)

Other

  • logos.available()
  • logos.deterministicKey(seed: string, index?: string | number)
  • logos.changeServer(nodeURL: string, proxyURL?: string)

Calling RPC directly

If there's a method missing, or if you prefer to call RPC directly, you can use logos.rpc. You'll still get the full benefit of type checking and return types for applicable RPC calls.

await logos.rpc('account_info', {account})