Search…
⌃K
🛠

3. How to Connect to Solana Web3JS

  1. 1.
    ) Add @solana/web3.js to your project:
  2. 2.
    yarn add @solana/web3.js OR npm install --save @solana/web3js
  3. 3.
    Include library in your files: const solanaWeb3 = require('@solana/web3.js');
  4. 4.
    ) Add RunNode connection string
var connection = new solanaWeb3.Connection(
'https://connect.runnode.com/?apikey=<API KEY GOES HERE>',
'confirmed',
);
if (connection) {
console.log('connected to RunNode successfully')
}
3. ) Make calls like you normally would:
let block = await connection.getBlock(slot);
console.log(block);