{"id":18304565,"url":"https://github.com/numtel/node-nano-node","last_synced_at":"2025-04-05T15:31:20.853Z","repository":{"id":57307797,"uuid":"119761751","full_name":"numtel/node-nano-node","owner":"numtel","description":"Nano currency (Formerly raiblocks) partial node for node.js","archived":false,"fork":false,"pushed_at":"2018-04-25T18:59:38.000Z","size":65,"stargazers_count":20,"open_issues_count":3,"forks_count":5,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-12T16:51:48.672Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/numtel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-01T00:37:10.000Z","updated_at":"2024-01-27T00:36:28.000Z","dependencies_parsed_at":"2022-09-17T22:21:42.325Z","dependency_job_id":null,"html_url":"https://github.com/numtel/node-nano-node","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fnode-nano-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fnode-nano-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fnode-nano-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fnode-nano-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/numtel","download_url":"https://codeload.github.com/numtel/node-nano-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247358646,"owners_count":20926264,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T15:29:20.877Z","updated_at":"2025-04-05T15:31:19.081Z","avatar_url":"https://github.com/numtel.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node.js Nano Node\n\n[![Build Status](https://travis-ci.org/numtel/node-nano-node.svg?branch=master)](https://travis-ci.org/numtel/node-nano-node)\n\nPartial (light, leech) Node for [Nano currency](https://nano.org) (Formerly [Raiblocks](https://raiblocks.net)) for Node.js.\n\n**Examples:**\n\n* [Pending](examples/pending.js): How to listen for new pending blocks on a specific account\n* [Receive](examples/receive.js): How to publish a block\n* [Pull](examples/pull.js): How to fetch an account blockchain history\n* [Votes](examples/votes.js): How to listen for representative votes\n* [State Blocks](examples/stateblocks.js): How to listen for state blocks\n\n## Table of Contents\n\n* [Installation](#installation)\n* [class NanoNode extends EventEmitter](#class-nanonode-extends-eventemitter)\n  * [Events Emitted](#events-emitted)\n  * [Properties](#properties)\n  * [constructor(port)](#constructorport)\n  * [publish(msg, accountKey, callback)](#publishmsg-accountkey-callback)\n  * [fetchAccount(publicKey, callback)](#fetchaccountpublickey-callback)\n  * [Static parseMessage(buf, minimalConfirmAck)](#static-parsemessagebuf-minimalconfirmack)\n  * [Static renderMessage(msg, accountKey)](#static-rendermessagemsg-accountkey)\n  * [Static keyFromAccount(account)](#static-keyfromaccountaccount)\n  * [Static accountFromKey(key)](#static-accountfromkeykey)\n  * [Static accountPair(seed, index)](#static-accountpairseed-index)\n\n## Installation\n\n```\nnpm install --save nano-node\n```\n\n## class NanoNode extends EventEmitter\n\n### Events Emitted\n\nName | Listener Arguments | Description\n-----|-------------------|-----------------------\n`message` | `msg`, `rinfo` | Network message received\n`block` | `block`, `rinfo` | Block received (messages of `publish` type)\n`vote` | `msg`, `rinfo` | Vote received (messages of `confirm_ack` type)\n`ready` | *None* | Server is listening\n`error` | `error` | An error has occurred\n\n### Properties\n\nMay be set after construction.\n\nName | Description\n-----|---------------\n`peers` | Array of strings containing hostname concatenated with a colon and the port\u003cbr\u003eDefault: `['rai.raiblocks.net:7075']`\n`maxPeers` | Maximum number of latest peers to publish new messages\u003cbr\u003eDefault: 200\n`minimalConfirmAck` | Parsing and validating each `confirm_ack` message as it arrives is very compute intensive due to the 2 blake2b hashes calculated on each receive. Set this value to `false` to parse and validate `comfirm_ack` messages. By default, (`true`) only the `account` public key is parsed.\n`tcpTimeout` | Duration to wait when performing TCP operations in milliseconds\u003cbr\u003eDefault: 4000\n\n### constructor(port)\n\n* `port` `\u003cInteger\u003e` Optional, random if unspecified\n\nCreate a new listening UDP service.\n\n### publish(msg, accountKey, callback)\n\n* `msg` `\u003cObject\u003e` Required, message definition, supports types `keepalive`, `publish`, `confirm_req`. May also pass fully rendered messages as `Buffer`.\n* `accountKey` `\u003cString\u003e` If `publish` message and no signature provided, pass account private key as hex string for block signing.\n* `callback` `\u003cFunction\u003e` Optional, callback function\n\nPublish a message to known peers. Known peers are managed automatically. Upon receiving a message, the peer is added to the top of the list. Up to `maxPeers` peers are kept.\n\n**Returns** only on `publish` and `confirm_req` messages: hex block hash\n\nPublishing regular `keepalive` messages is important to continure receiving messages:\n\n```js\nconst NanoNode = require('nano-node');\nconst node = new NanoNode();\nsetInterval(() =\u003e {\n  console.log('Sending keepalive to ', node.peers.length, 'peers...');\n  node.publish({type: 'keepalive'});\n}, 30000);\n```\n\n#### Message Properties\n\n\nName | Default | Type | Description\n-----|--------|-------|--------------\n`type` | *None* | String | Required, `keepalive` or `publish`\n`mainnet` | `true` | Boolean | Optional, True (default) for mainnet, false for testnet\n`versionMax` | `7` | Integer | Optional\n`versionUsing` | `7` | Integer | Optional\n`versionMin` | `1` | Integer | Optional\n`extensions` | `0` | Integer | Optional, overwritten with block type for `publish` messages\n`body` | *None* | Object | Required for `publish` messages\n\n#### Publish Body Object Properties\n\n\nName | Required Types | Type | Description\n-----|----------------|----|---\n`type` | *All* | String | `send`, `receive`, `open`, `change`, `state`\n`previous` | `send`, `receive`, `change`, `state` | 64 character hex string | Hash of previous block in account\n`destination` | `send` | 64 character hex string | Account public key of recipient\n`balance` | `send`, `state` | 32 character hex string | New balance of account\n`source` | `receive`, `open` | 64 character hex string | Hash of pending `send` block\n`representative` | `open`, `change`, `state` | 64 character hex string | Public key of representative account to assign\n`account` | `open`, `state` | 64 character hex string | Public key of the current account\n`link` | `state` | 64 character hex string | Public key of the current account\n`signature` | *Optional* | 128 character hex string | Pass precomputed signature in this property. Otherwise, pass `accountKey` argument for block signing.\n`work` | *All* | 16 character hex string | Required for all block types, calculated from account public key for `open` type blocks, previous block hash for all other block types. See [raiblocks-pow NPM package](https://github.com/numtel/node-raiblocks-pow) for generating this value.\n\n### fetchAccount(publicKey, callback)\n\n* `publicKey` `\u003cString\u003e` Required, account public key to fetch block history\n* `callback` `\u003cFunction\u003e` `error, result`\n\nConnect to known peers over TCP and send a `bulk_pull` message for a single account. Wait until timeout from `tcpTimeout` property, then determine the longest valid chain returned.\n\nWithout a full lattice database, the balance of an account can not be determined unless the frontier block is a `send` block.\n\n**Result object properties:**\n\nName | Type | Description\n----|-------|--------------\n`blocks`| Array | Transaction history sorted newest to oldest\n`matchProportion`| Number | Between 0 and 1 indicating the proportion of peer responses that match this chain. A value of 1 means all responding peers agree on this length.\n`returnCount`| Number | Count of peer responses returned before timeout\n\n### Static parseMessage(buf, minimalConfirmAck)\n\n* `buf` `\u003cBuffer\u003e` Required, full UDP message\n* `minimalConfirmAck` `\u003cBoolean\u003e` Optional, default: true. Only parse account value of vote (confirm_ack) messages\n\nReturns an object with the properties of the message\n\n### Static renderMessage(msg, accountKey)\n\nUseful for obtaining a block's hash without publishing it yet.\n\n* `msg` `\u003cObject\u003e` Required, message properties as described above\n* `accountKey` `\u003cString\u003e` Required to sign blocks for `publish`, `confirm_req` messages, otherwise provide signature property\n\nReturns an object `{ message: \u003cBuffer\u003e, hash: \u003cString|null\u003e }` `hash` is block hash if available\n\n### Static keyFromAccount(account)\n\n* `account` `\u003cString\u003e` Required, account address to convert\n\nReturn the public key for a given address\n\n### Static accountFromKey(key)\n\n* `key` `\u003cString\u003e` Required, public key to convert\n\nReturn the address for a given account public key\n\n### Static accountPair(seed, index)\n\n* `seed` `\u003cString|Buffer\u003e` Required, wallet seed as 32 byte Buffer or 64 character hex string\n* `index` `\u003cNumber\u003e` Required, 32-bit unsigned integer specifying account index\n\nReturns an object `{privateKey: \u003cString\u003e, publicKey: \u003cString\u003e, address: \u003cstring\u003e}`\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumtel%2Fnode-nano-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnumtel%2Fnode-nano-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumtel%2Fnode-nano-node/lists"}