Neptune Cash JS is a community-made wrapper
for neptune-core JSON RPC API
requests. Currently, it supports
first 20 implemented API methods
in both Neptune Cash and Neptune Privacy. Licensed under Apache-2.0.
Important
To see README.md or source code of your version please checkout to the right tag.
The npm packages already contain the right data.
I assume, that you have already used libraries like ethers or viem and
know how JSON-RPC works. Also, I hope you are a little bit familiar
with neptune-core.
First of all, install the library using:
npm install neptune-cashNext, create a client object:
import {NeptuneClient} from "neptune-cash"
const neptune = new NeptuneClient()Note, that you aren't connect with the server immediately. The connection happens every time when you invoke methods.
The constructor takes two parameters:
hostName- host name of the RPC server, defaultlocalhostport- port of the RPC server, default9797(notice that the default port for the XNT is9897)
To create your own server check Configuring RPC server. If you don't like to, you can
use mine - hostName: 217.160.149.196 with default port 🙂
The NeptuneClient class provides two kinds of async methods:
-
with
safeprefix - they return error (if occurred) as a field of an object:{ success: true, data: T } | { success: false, error: JSONRPCErrorType | RequestErrorType }
In this case I was inspired by zod. See src/types/internal.ts for more details.
-
without
safeprefix - these methods can throw instance of class extendingErrorif error occurred.
The library provides following classes for error handling (no other errors can be thrown):
- RequestError - extends
Error- responsible for network errors, e.g. invalid port or no internet connection. - JSONRPCError - extends
Error, responsible for errors from RPC responses. Also parent class for two following:- MethodNotFoundError - thrown when your server doesn't support a given method.
- InvalidParamsError - thrown when params you provided to method are invalid. Types of method arguments aren't perfect so this error can occur often.
-
Download
neptune-core 0.5.0from here. -
Sync your node with the network:
neptune-core --peer <address>
To get currently working peers you can search the internet or ask someone on the Neptune Cash Telegram. You can use many
--peerwith other addresses. -
Run the server:
neptune-core --listen-rpc --peer <address> --rpc-modules "chain,node,archival"
This command will start the server with all modules (and methods) supported by the library.
-
Download
xnt-core 0.1.0from here. -
Sync your node with the network:
xnt-core --peer <address>
To get currently working peers you can search the internet or ask someone on the Neptune Privacy Telegram. You can use many
--peerwith other addresses. -
Run the server:
xnt-core --listen-rpc --peer <address> --rpc-modules "chain,node,archival"
This command will start the server with all modules (and methods) supported by the library.
-
Neptune Cash
const neptune = new NeptuneClient("217.160.149.196", DEFAULT_NEPTUNE_CASH_PORT);
-
Neptune Privacy (XNT)
const neptune = new NeptuneClient("217.160.149.196", DEFAULT_XNT_PORT);
Remember to provide the right imports!
neptune-core 0.5.0modules:chain,node,archivalxnt-core 0.1.0modules:chain,node,archival
Some of the newer features may not work.
The whole library is based on the ofetch. Also, I've used ts-node as a dev
dependency.
If you have any questions/suggestions feel free to message me on Telegram, or Discord: @comradecobweb. You can also
open an issue!
API Docs
Kaffin's PR
message.rs
https.rs
ops.rs
XNT source code