PREVIEW RELEASE This is a beta preview release with breaking changes! The current version is 1.0.0
Nanjs - JavaScript API
This is the Nanjs JavaScript API which connects to the Nanj-coin system.
Building
Features
- Create NANJ Wallet
- Import NANJ Wallet via Private Key / Key Store
- Export Private Key/ Key Store from NANJ Wallet
- Generate NANJ Address
- Generate QRCode from Wallet Address
- Generate Hash Sign
- Get NANJ Rate
- Get NANJ Balance
Requirements
- Node.js
- npm
Installation
/directory/your-project$ npm install nanjs
Set config file
/directory/your-project$ cp .env.example .env
API
(static) init
var nanjs =
createWallet(): Create Wallet
/* It's a async function1. generate address from mnemonic2. password default is 1234567893. options kdf */var mnemonic = nanjswalletvar password = '123456789' var options = kdf: "scrypt" // or "pbkdf2" to use the pbkdf2 kdf cipher: "aes-128-ctr" kdfparams: n: 8192 r: 8 p: 1 console
The createWallet
function is used to export key info to keystore "secret-storage" format.
importWallet(): Import Wallet
// It's a async function// generate address from mnemonicvar mnemonic = 'brain surround have swap horror body response double fire dumb bring hazard'var password = '123456789'console
Generate NANJ Address
// It's a async function// generate nanj addressvar address = '0xe79c03e29ee86c1d0af6053737dccb029402d0f3'var privateKey = '0541a5d81178f67887203996fe596b4fd3de72244e86a371e295f660aab0f039'nanjswallet
Get NANJ Balance
// Get NANJ Balancevar address = '0xe79c03e29ee86c1d0af6053737dccb029402d0f3' nanjswallet
Generate QRCode from Wallet Address
// Generate QRCode// Response is a base64 image var address = '0xe79c03e29ee86c1d0af6053737dccb029402d0f3' nanjswallet // Using in html: <img src="base64Url">
Generate Hash Sign
/** * It's a async function * dataHash have dest, hash, data, v, r, s, nonce */ var from = '0xe79c03e29ee86c1d0af6053737dccb029402d0f3'var privateKey = '0541a5d81178f67887203996fe596b4fd3de72244e86a371e295f660aab0f039'var to = '0xfce1759a46647adfe4f9564320631c4f0a90deba'var amount = 5var message = 'nanj transaction'var nonce = processenvNANJ_HOST+processenvPATH_RELAY_NONCE+'?sender='+from var txHash = await nanjstransactionvar dataHash = await nanjstransaction console
Testing (mocha)
npm test
Versioning
For the versions available, see the tags on this repository.
Acknowledgements
Inspired by code from the following great projects:
- https://www.npmjs.com/package/eth-hd-wallet
- https://github.com/ConsenSys/eth-lightwallet
- https://nanjcoin.com/sdk
Authors
- NANJ TEAM NANJ, support@nanjcoin.com