nanopow-rs-node
A JavaScript wrapper for nanopow-rs to provide fast, safe, fully multithreaded Nano proof-of-work generation in Node.js.
Usage
First: Install Rust
See https://www.rustup.rs/ for instructions on installing Rust for your system.
With Node
$ yarn add nanopow-rs-node
$ yarn install
In Electron App
Basically same as above, see https://guides.neon-bindings.com/electron-apps/
Example
const nanopow = require('nanopow-rs-node')
const hash = 'AC101449364C84CDD7562AA724BE52757EF06BCE834C50CF610DD2949291B0D9'
nanopow.generateWork(hash)
.then(work => {
const isValid = nanopow.checkWork(hash, work)
})
nanopow.generateWork(hash, 10000000)
.then(work => {
const isValid = nanopow.checkWork(hash, work)
console.log(`Found valid work: ${work}`)
})
.catch(err => {
console.error(`Failed to find work in 10 million iterations`)
})
async function myTransactionFunction (hash) {
const work = await nanopow.generateWork(hash)
const isValid = nanopow.checkWork(hash, work)
}
async function myTransactionFunction (hash) {
try {
const work = await nanopow.generateWork(hash, 10000000)
const isValid = nanopow.checkWork(hash, work)
console.log(`Found valid work: ${work}`)
} catch (e) {
console.error(`Failed to find work in 10 million iterations`)
}
}
const work = nanopow.generateWorkSync(hash)
const isValid = nanopow.checkWork(hash, work)
const work = nanopow.generateWorkSync(hash, 10000000)
const isValid = nanopow.checkWork(hash, work)
API Reference
nanopow.generateWork (hash, maxIters)
nanopow.generateWorkSync (hash, maxIters)
nanopow.checkWork(hash, work)
Development
Install needed deps with
$ yarn install
Tests in test/test.js
, perfom tests with
$ yarn test
Reference
See Neon docs and examples in their tests directory on GitHub