nexajs
v24.11.15
Published
A comprehensive JavaScript Library + SDK for building Nexa applications on Node.js (back-end) and web browsers (front-end).
Downloads
252
Readme
NEXA.js
https://nexajs.org
A pure JavaScript Library and Software Development Kit (SDK) for building decentralized applications (dApps) powered by the Nexa blockchain.
Released under the terms of the MIT LICENSE.
Documentation
Our docs are updated regularly.
https://docs.nexajs.org
Table of contents
- Quick Start
- Introduction
- Installation
- Should I use this in Production?
- Can I trust this Code?
- Usage
- Examples
- Packages List
- Contributing
- Complementing Libraries
Quick Start
To quickly get started using Nexa in your existing Webapp, simply include this tag in the section of your HTML:
Web2 (CDN) Installation
<!-- CDN (Web2) integration solution -->
<script src="https://cdn.nexajs.org/nexa.min.js"
integrity="sha384-qBLa2DVAThYbLO3kajnReZVS5cG3m3swWmBL0tNN7CxvzgRZQw/cfwsmbXOGma7K"
crossorigin="anonymous"></script>
Web3 (IPFS) Installation
<!-- IPFS Gateway (Web3) integration solution -->
<script src="https://bafybeifohi5njjlohhkwcsola3346cn3ngyaqyl5bwn5k7a4mbvtzy4y3m.ipfs.dweb.link/"
integrity="sha384-qBLa2DVAThYbLO3kajnReZVS5cG3m3swWmBL0tNN7CxvzgRZQw/cfwsmbXOGma7K"
crossorigin="anonymous"></script>
Web4 (CAPD | Nostr) Installation
<!-- Counterparty and Protocol Discovery (Web4) integration solution -->
<script src="proto://9addf9bc724b2e14094950598918dde63b091253e6106b7d9716nexaverse888"></script>
Package Manager Installation
npm install --save nexajs
yarn add nexajs
pnpm install nexajs
WARNING: We presently don't provide any tooling to verify that the release on npm
matches GitHub. As such, you should verify anything downloaded by npm
against your own verified copy.
Introduction
The NEXA.js Library + SDK aims to be a modern & comprehensive toolkit for creating decentralized applications (dApps) on the Nexa Blockchain and its expansive Web3 ecosystem.
Prerequisites
- Node v12+
Requirements
- Basic JavaScript knowledge
Installation
npm install nexajs
Building the Workspace
Install your preferred Integrated Development Environment (IDE) or text editor, eg:
- Visual Studio Code (VSC)
- Atom
- Sublime
Example file: send-tx.js
import Nexa from 'nexajs'
const privateKey = new Nexa.PrivateKey('L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy')
const utxo = {
txId : '115e8f72f39fad874cfab0deed11a80f24f967a84079fb56ddf53ea02e308986',
outputIndex : 0,
address : '17XBj6iFEsf8kzDMGQk5ghZipxX49VXuaV',
script : '76a91447862fe165e6121af80d5dde1ecb478ed170565b88ac',
satoshis : 50000,
}
const transaction = new Nexa.Transaction()
.from(utxo)
.to('1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK', 15000)
.sign(privateKey)
From the terminal / command-line:
$ node examples/send-tx.js
Should I use this in Production?
If you are thinking of using the master branch of this library in production, stop. Master is not stable; it is our development branch, and only tagged releases may be classified as stable.
Can I trust this Code?
Don't trust. Verify.
We recommend every user of this library and the nexajs ecosystem audit and verify any underlying code for its validity and suitability, including reviewing any and all of your project's dependencies.
Mistakes and bugs happen, but with your help in resolving and reporting issues, together we can produce open source software that is:
- Easy to audit and verify,
- Tested, with test coverage >95%,
- Advanced and feature rich,
- Standardized, using prettier and Node
Buffer
's throughout, and - Friendly, with a strong and helpful community, ready to answer questions.
Usage
Crypto is hard.
When working with private keys, the random number generator is fundamentally one of the most important parts of any software you write.
For random number generation, we default to the randombytes
module, which uses window.crypto.getRandomValues
in the browser, or Node js' crypto.randomBytes
, depending on your build system.
Although this default is ~OK, there is no simple way to detect if the underlying RNG provided is good enough, or if it is catastrophically bad.
You should always verify this yourself to your own standards.
Finally, adhere to best practice. We are not an authorative source of best practice, but, at the very least:
- ~~Don't re-use addresses~~.
- Don't share BIP32 extended public keys ('xpubs'). They are a liability, and it only takes 1 misplaced private key (or a buggy implementation!) and you are vulnerable to catastrophic fund loss.
- Don't use
Math.random
- in any way - don't. - Enforce that users always verify (manually) a freshly-decoded human-readable version of their intended transaction before broadcast.
- Don't ask users to generate mnemonics, or 'brain wallets', humans are terrible random number generators.
Browser
The recommended method of using nexajs-lib
in your browser is through Browserify.
If you're familiar with how to use browserify, ignore this and carry on, otherwise, it is recommended to read the tutorial at https://browserify.org/.
NOTE: We use Node Maintenance LTS features, if you need strict ES5, use --transform babelify
in conjunction with your browserify
step (using an es2015
preset).
WARNING: iOS devices have problems, use at least [email protected] or greater, and enforce the test suites (for Buffer
, and any other dependency) pass before use.
Examples
The below examples are implemented as integration tests, they should be very easy to understand. Otherwise, pull requests are appreciated. Some examples interact (via HTTPS) with a 3rd Party Blockchain Provider (3PBP).
- Generate a random address
- Import an address via WIF
- Generate a 2-of-3 P2SH multisig address
- Generate a Testnet address
- Create a 1-to-1 Transaction
- Import a BIP32 testnet xpriv and export to WIF
- Export a BIP32 xpriv, then import it
- Export a BIP32 xpub
- Use BIP39 to generate BIP32 addresses
If you have a use case that you feel could be listed here, please ask for it!
Packages List
The following suite of 26 packages compose the entire NEXA.js Library and Software Development Kit (SDK).
- [ ] Account
- [x] Address
- [ ] App
- [ ] Blockchain
- [ ] Charts
- [x] Crypto
- [ ] DeFi
- [ ] Express
- [ ] Games
- [x] HD Node
- [x] Nexa ID
- [ ] Ledger HW Wallet
- [x] Market
- [ ] Meta
- [ ] Privacy
- [x] Purse
- [x] Rostrum
- [x] RPC
- [x] Script
- [ ] Server
- [ ] Slim
- [x] Token
- [x] Transaction
- [ ] Trezor HW Wallet
- [x] Utils
- [x] Wallet
- NOTE: Not all packages are published to the NPM registry.
NPM Repository Deployment
cd nexajs/lib/package/<package-name>
rm -rf node_modules/ yarn.lock
yarn
# update package.json version
# !cdn, !daemon, !yarn.lock
npm publish
Contributing
See CONTRIBUTING.md.
Running the Test Suite
npm test
npm run-script coverage
Similar Libraries
- Nexcore Lib — a fork of Bitcore Lib Cash library with changes to make it work for Nexa project.