@neuraiproject/neurai-rpc 0.4.1 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.ts CHANGED
@@ -63,9 +63,9 @@ export function getRPC(username: string, password: string, URL: string) {
63
63
  rejectionFunc({
64
64
  originalError: e,
65
65
  type: "ServerUnreachable",
66
- error: "Could not communicate with Raven core node",
66
+ error: "Could not communicate with Neurai core node",
67
67
  description:
68
- "Are you sure that the URL is correct? The URL is usually mainnet = http://127.0.0.1:19001 and testnet = http://127.0.0.1:119001",
68
+ "Are you sure that the URL is correct? The URL is usually mainnet = http://127.0.0.1:19001 and testnet = http://127.0.0.1:19101",
69
69
  });
70
70
  });
71
71
  } catch (e) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@neuraiproject/neurai-rpc",
3
- "version": "0.4.1",
4
- "description": "Helps you access your Ravencoin full node using RPC from JavaScript",
3
+ "version": "0.4.3",
4
+ "description": "Helps you access your Neurai full node using RPC from JavaScript",
5
5
  "types": "dist/types.d.ts",
6
6
  "type": "module",
7
7
  "source": "index.ts",
@@ -30,7 +30,7 @@
30
30
  "devDependencies": {
31
31
  "@parcel/packager-ts": "^2.12.0",
32
32
  "@parcel/transformer-typescript-types": "^2.12.0",
33
- "@types/node": "^18.0.45",
33
+ "@types/node": "^18.19.130",
34
34
  "buffer": "^6.0.3",
35
35
  "jest": "^29.7.0",
36
36
  "parcel": "^2.12.0",
@@ -0,0 +1,149 @@
1
+ // Test real connection to local Neurai node and getpubkey RPC method
2
+
3
+ import { methods, getRPC } from './dist/index.mjs';
4
+
5
+ console.log('=== Testing getpubkey RPC Method ===\n');
6
+
7
+ // Configuration for local node
8
+ const username = '123';
9
+ const password = '123';
10
+ const url = 'http://127.0.0.1:19001';
11
+
12
+ // Get address from command line argument
13
+ const testAddress = process.argv[2];
14
+
15
+ console.log('Connecting to:', url);
16
+ console.log('Username:', username);
17
+ console.log('');
18
+
19
+ // Initialize RPC connection
20
+ const rpc = getRPC(username, password, url);
21
+
22
+ // First, test basic connection with getblockcount
23
+ console.log('1. Testing basic connection with getblockcount...');
24
+ try {
25
+ const blockCount = await rpc('getblockcount', []);
26
+ console.log('✓ Connection successful!');
27
+ console.log(' Current block count:', blockCount);
28
+ console.log('');
29
+ } catch (error) {
30
+ console.log('✗ Connection failed!');
31
+ console.log(' Error:', error.error ? error.error.message : error.message);
32
+ console.log('');
33
+ console.log('Please verify:');
34
+ console.log(' 1. Neurai node is running');
35
+ console.log(' 2. RPC server is enabled');
36
+ console.log(' 3. Username and password are correct in neurai.conf');
37
+ console.log(' 4. rpcallowip is configured (e.g., rpcallowip=127.0.0.1)');
38
+ process.exit(1);
39
+ }
40
+
41
+ // Test getpubkey method
42
+ console.log('2. Testing getpubkey method...');
43
+ console.log('');
44
+
45
+ if (testAddress) {
46
+ // Test with provided address
47
+ console.log(` Testing address: ${testAddress}`);
48
+
49
+ try {
50
+ const result = await rpc('getpubkey', [testAddress]);
51
+
52
+ console.log(' ✓ Success!');
53
+ console.log(' - Address:', result.address);
54
+ console.log(' - Revealed:', result.revealed);
55
+
56
+ if (result.revealed) {
57
+ console.log(' - Public Key:', result.pubkey);
58
+ console.log(' - Height:', result.height);
59
+ console.log(' - TxID:', result.txid);
60
+ } else {
61
+ console.log(' - Note: This address has not spent funds yet');
62
+ console.log(' Public key will be revealed after first spend');
63
+ }
64
+ console.log('');
65
+
66
+ } catch (error) {
67
+ if (error.error && error.error.message) {
68
+ if (error.error.message.includes('Pubkey index not enabled')) {
69
+ console.log(' ✗ Error: Pubkey index not enabled');
70
+ console.log(' Add "pubkeyindex=1" to your neurai.conf and restart the node');
71
+ console.log(' Then reindex with: neurai-cli -reindex');
72
+ } else if (error.error.message.includes('Invalid address')) {
73
+ console.log(' ✗ Error: Invalid address');
74
+ console.log(' Please provide a valid Neurai address');
75
+ } else {
76
+ console.log(' ✗ Error:', error.error.message);
77
+ }
78
+ } else {
79
+ console.log(' ✗ Error:', error.message || error);
80
+ }
81
+ console.log('');
82
+ }
83
+ } else {
84
+ // Test with addresses from wallet
85
+ console.log(' No address provided, checking wallet addresses...');
86
+ console.log('');
87
+
88
+ try {
89
+ const addresses = await rpc('listreceivedbyaddress', [0, true]);
90
+
91
+ if (addresses.length === 0) {
92
+ console.log(' No addresses found in wallet.');
93
+ console.log(' Generate a new address with: neurai-cli getnewaddress');
94
+ console.log(' Or provide an address: node test-getpubkey.js <address>');
95
+ console.log('');
96
+ } else {
97
+ console.log(` Found ${addresses.length} addresses in wallet`);
98
+ console.log(' Testing first 3 addresses...');
99
+ console.log('');
100
+
101
+ const testAddresses = addresses.slice(0, 3);
102
+
103
+ for (const addrInfo of testAddresses) {
104
+ const address = addrInfo.address;
105
+ console.log(` Testing address: ${address}`);
106
+
107
+ try {
108
+ const result = await rpc('getpubkey', [address]);
109
+
110
+ console.log(' ✓ Success!');
111
+ console.log(' - Revealed:', result.revealed);
112
+
113
+ if (result.revealed) {
114
+ console.log(' - Public Key:', result.pubkey);
115
+ console.log(' - Height:', result.height);
116
+ console.log(' - TxID:', result.txid);
117
+ } else {
118
+ console.log(' - Note: This address has not spent funds yet');
119
+ console.log(' Public key will be revealed after first spend');
120
+ }
121
+ console.log('');
122
+
123
+ } catch (error) {
124
+ if (error.error && error.error.message) {
125
+ if (error.error.message.includes('Pubkey index not enabled')) {
126
+ console.log(' ✗ Error: Pubkey index not enabled');
127
+ console.log(' Add "pubkeyindex=1" to your neurai.conf and restart the node');
128
+ console.log(' Then reindex with: neurai-cli -reindex');
129
+ break;
130
+ } else {
131
+ console.log(' ✗ Error:', error.error.message);
132
+ }
133
+ } else {
134
+ console.log(' ✗ Error:', error.message || error);
135
+ }
136
+ console.log('');
137
+ }
138
+ }
139
+ }
140
+ } catch (error) {
141
+ console.log(' Error getting addresses:', error.error ? error.error.message : error.message);
142
+ console.log('');
143
+ }
144
+ }
145
+
146
+ console.log('=== Test Complete ===');
147
+ console.log('');
148
+ console.log('Usage: node test-getpubkey.js [address]');
149
+ console.log('Example: node test-getpubkey.js NTVDv81nvwEKpCqhrNwjypTEKMYdpiDKKV');
package/test.js ADDED
@@ -0,0 +1,56 @@
1
+ const NeuraiRPC = require("./dist/index.cjs");
2
+
3
+ test("3rd party service getblockcount", async () => {
4
+ const rpc = NeuraiRPC.getRPC(
5
+ "anon",
6
+ "anon",
7
+ "https://rpc-main.neurai.org/rpc"
8
+ );
9
+ let count = 0;
10
+ try {
11
+ count = await rpc("getblockcount", []);
12
+ } catch (e) {}
13
+
14
+ const countMoreThanZero = count > 0;
15
+ expect(countMoreThanZero).toBe(true);
16
+ });
17
+
18
+ test("3rd party service incorrect method", async () => {
19
+ const rpc = NeuraiRPC.getRPC(
20
+ "anon",
21
+ "anon",
22
+ "https://rpc-main.neurai.org/rpc"
23
+ );
24
+ const method = "getblockcountWRONG";
25
+ const params = [];
26
+
27
+ let theError = null;
28
+ try {
29
+ const count = await rpc(method, params);
30
+ } catch (e) {
31
+ theError = e;
32
+ }
33
+
34
+ expect(!!theError).toBe(true);
35
+ expect(theError.error).toBe("Not in whitelist");
36
+ expect(theError.description).toBe(
37
+ "Method getblockcountWRONG is not supported"
38
+ );
39
+ });
40
+
41
+ test("Non existing 3rd party service getblockcount", async () => {
42
+ const rpc = NeuraiRPC.getRPC(
43
+ "anon",
44
+ "anon",
45
+ "https://rpc-main.neurai.org/rpc"
46
+ );
47
+
48
+ let error = null;
49
+ try {
50
+ const count = await rpc("getblockcount", []);
51
+ } catch (e) {
52
+ error = e;
53
+ }
54
+
55
+ expect(!!error).toBe(true);
56
+ });