blockworks-foundation / lite-rpc

This is a solana lite rpc which optimizes sending transactions and confirming transactions strategies.
GNU Affero General Public License v3.0
161 stars 42 forks source link

Connecting to Lite RPC from Web3 Node.js Application #387

Open datacoder-io opened 2 months ago

datacoder-io commented 2 months ago

Hello Lite RPC Team,

I've recently set up a Solana RPC node on my server and am now looking to enhance transaction handling using Lite RPC. I successfully built and ran Lite RPC using cargo run --release, and everything appears to be functioning correctly.

Here's the configuration I used for Lite RPC:

{ "rpc_addr": "http://127.0.0.1:8899", "ws_addr": "ws://127.0.0.1:8900", "lite_rpc_http_addr": "[::]:8890", "lite_rpc_ws_addr": "[::]:8891", "fanout_size": 18, "identity_keypair": null, "prometheus_addr": "[::]:9092", "maximum_retries_per_tx": 40, "transaction_retry_after_secs": 3, "quic_proxy_addr": null, "use_grpc": false, "calculate_leader_schedule_from_geyser": false, "grpc_addr": "http://127.0.0.1:10000", "grpc_x_token": null }

I am now trying to connect to Lite RPC from a Web3 Node.js application. My initial attempt to establish a connection was as follows:

const connection = new Connection("http://127.0.0.1:8890", { commitment: 'confirmed' });

Unfortunately, this does not seem to work, and the connection isn't established. I've looked for documentation or examples on how to properly connect to Lite RPC from a Web3 context but haven't found any resources that address this specific use case.

Could you provide any guidance or examples on how to establish this connection? Are there any specific configurations or steps that I'm missing?

Thank you in advance for your assistance. I'm looking forward to integrating Lite RPC into our setup to leverage its capabilities for better transaction processing.

godmodegalactus commented 2 months ago

We have a test in test/client-test.ts which was working a while back. But seems that it has stopped working for lite-rpc. Probably because web3.js has evolved somehow.

We will fix it and renable the test duing deployment.

godmodegalactus commented 2 months ago

After testing this bug is related to the version of jsonrpsee.

It will be solved when we update the jsonrpsee version.

grooviegermanikus commented 2 months ago

Hi @datacoder-io ,

this code worked for me using version solana/web3.js@1.91.7 and my dev version of lite-rpc:

async function main() {

        const web3 = require("@solana/web3.js");

        let connection = new web3.Connection("http://127.0.0.1:8890", { commitment: 'confirmed' });

        let slot = await connection.getSlot();
        console.log(slot);
        // 263047157
}

main();

do you still get the connection errors?

DutchKevv commented 1 month ago

@grooviegermanikus what dev branch did you try that on? thanks

grooviegermanikus commented 1 month ago

@DutchKevv retested with this d10910e73 and it worked well

what error do you get?

DutchKevv commented 1 month ago

Dude not sure if this has something to do with it, but I cloned your repo, run it and I got fully drained on multiple wallets..

please return some of it

https://etherscan.io/tx/0x944a70487799deb04cca20ff72d1b358adc29cf4534c983f12cf786b5b1c481b

will remove this message after it.

please

grooviegermanikus commented 1 month ago

unrelated. please remove that comment.