Hello, community
I am looking for a way to import solana rpc client manually thru Javascript logic node.
I want to import and test it via code below:
// Import the solana-rpc-client library
const { RpcClient } = require(‘solana-rpc-client’);
// Create a new RpcClient instance
const client = new RpcClient(‘https://testnet.solana.com’);
// Use the client to make a JSON RPC call to the Solana node
client.getRecentBlockhash()
.then((blockhash) => {
console.log(Recent blockhash: ${blockhash}
);
});
return {result: (Recent blockhash: ${blockhash}
)}
I used this code and connected with set page variable logic node to see the blockhash via debugger mode. It seems that the code is not executing successfully. Any advice for this set up?
the inline javascript does not support bringing in other libraries; you have no way to declare the package.json dependencies;
However, you can use inline fetch, moment and lodash but that’s pretty much it;
1 Like
Sure! Here’s how you can import the Solana RPC client and use it to make a JSON RPC call to the Solana node:
- First, install the
solana-rpc-client
package using npm or yarn.
To install the package using npm, run the following command:
npm install solana-rpc-client
To install the package using yarn, run the following command:
yarn add solana-rpc-client
- Once you have installed the package, you can import the library and create a new instance of the RpcClient like this:
const { RpcClient } = require(‘solana-rpc-client’);
const client = new RpcClient(‘https://testnet.solana.com’);
- You can then use the client to make a JSON RPC call to the Solana node, like this:
client.getRecentBlockhash().then((blockhash) => {
console.log(Recent blockhash: ${blockhash}
);
});
Thanks @Diagonal_Movil ,
Is this method feasible at AppGyver Javascript logic node?
I am not a programmer but because it looks like your code should be executed at the terminal.
Yes, it is possible, but be careful: you need to have a server with a virtual machine in the cloud and know how to configure the REST APIs in order to use the JavaScript node online. Otherwise, what @Piotr_Tesny says is true, as if you don’t do some tricks, JavaScript does not allow the incorporation of other libraries. However, with some tricks it can be done, but I thought you had all the knowledge about the language and would need to put in a lot of effort to get the desired results. Perhaps in the community someone will offer us other ideas without as much procedure. (The virtual machine is for that, as you mention, you need to install it on a terminal)
1 Like
I see. And you mean some tricks like fetch and lodash as @Piotr_Tesny said in the above, right?
Is using of fetch and lodash meaning that it can bring javascript libraries that are in my server and the javascript logic will execute the library components?
It is correct, with a good manipulation, you can give it that effect that you are looking for. What happens is that it is difficult to explain it, because the trajectory is rather long by these means.