Home > database >  How to access JSON RPC API Solana Javascript in Linux Envoirment?
How to access JSON RPC API Solana Javascript in Linux Envoirment?

Time:09-21

I am trying to access the SOLANA API, specifically from this GitHub: https://github.com/solana-labs/solana-web3.js with all these actions: https://solana-labs.github.io/solana-web3.js/ and read the Solana documentation here: https://docs.solana.com/developing/clients/jsonrpc-api and I have also successfully installed the Solana CLI like so: https://docs.solana.com/cli/install-solana-cli-tools here is my code in the Linux environment:

sudo apt update
git clone https://github.com/solana-labs/solana-web3.js.git
cd solana-web3.js
yarn add @solana/web3.js

I don't get any errors, everything went fine and all dependence and modules are installed. I the create the javascript file like so:

const solanaWeb3 = require('@solana/web3.js');
console.log(solanaWeb3);

My question is how do I finally connect to the API and get to use all these methods: https://solana-labs.github.io/solana-web3.js/.

Do I need to use curl or how do I connect to the API?

CodePudding user response:

If you're using @solana/web3.js, then you're looking to develop in a NodeJS environment. You've added @solana/web3.js to your project, so the next part is to use it!

You can start by copy / pasting this example which creates an account and sends SOL from one account to another: https://github.com/solana-labs/solana/blob/master/web3.js/examples/send_sol.js

So in this case, you won't need to use curl, and instead you can use all of the functions and types that exist in the web3.js library from your Node project.

  • Related