Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xrpl.js v4.x throws errors on some networks/servers #2872

Open
mDuo13 opened this issue Jan 7, 2025 · 2 comments · May be fixed by #2877
Open

xrpl.js v4.x throws errors on some networks/servers #2872

mDuo13 opened this issue Jan 7, 2025 · 2 comments · May be fixed by #2877

Comments

@mDuo13
Copy link
Collaborator

mDuo13 commented Jan 7, 2025

When connecting to certain networks, Client.connect() throws API version errors. I've observed this with Batch Devnet and Xahau currently.

Tested on: xrpl@4.1.0

Try the following in the node console:

const xrpl = require("xrpl")
const batchClient = new xrpl.Client("wss://batch.nerdnest.xyz")
await batchClient.connect()

Expected result: successful connection with no error.

Actual result:

RippledError: invalid_API_version
    at RequestManager.handleResponse (/another/devel/workspaces/xrpljs4/node_modules/xrpl/dist/npm/client/RequestManager.js:104:27)
    at Connection.onMessage (/another/devel/workspaces/xrpljs4/node_modules/xrpl/dist/npm/client/connection.js:190:37)
    at Socket.<anonymous> (/another/devel/workspaces/xrpljs4/node_modules/xrpl/dist/npm/client/connection.js:209:53)
    at Socket.emit (node:events:518:28)
    at Socket.emit (node:domain:552:15)
    at Receiver.receiverOnMessage (/another/devel/workspaces/xrpljs4/node_modules/ws/lib/websocket.js:1220:20)
    at Receiver.emit (node:events:518:28)
    at Receiver.emit (node:domain:552:15)
    at Receiver.dataMessage (/another/devel/workspaces/xrpljs4/node_modules/ws/lib/receiver.js:596:14)
    at /another/devel/workspaces/xrpljs4/node_modules/ws/lib/receiver.js:530:12 {
  data: {
    api_version: 2,
    error: 'invalid_API_version',
    id: 0,
    request: { api_version: 2, command: 'server_info', id: 0 },
    status: 'error',
    type: 'response'
  }
}

It appears that after this error, it is successfully connected, but requests fail unless you explicitly specify api_version: 1 in them.

There should probably be a way to specify in the constructor not to use api_version: 2 in case you're connecting to a server that you know doesn't support API v2. Possibly also, the client should catch the above error and switch to APIv1 mode automatically, or something like that.

@tequdev
Copy link
Contributor

tequdev commented Jan 11, 2025

This problem can be solved by specifying the apiVersion before connect().

const xrpl = require("xrpl")
const batchClient = new xrpl.Client("wss://batch.nerdnest.xyz")
batchClient.apiVersion = 1
await batchClient.connect()

It would be very useful if it could be switched automatically.

@nixer89
Copy link
Collaborator

nixer89 commented Jan 15, 2025

I just stumbled across the same issue (well, I rather wanted to define the apiVersion in a central place instead of adding it to ever request)

I think a nice place would be to add this to the constructor's ClientOptions:

export interface ClientOptions extends ConnectionUserOptions

so one could use: const client = new Client("wss://test.com", { apiVersion: 1 } )

@tequdev tequdev linked a pull request Jan 16, 2025 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants