In your project folder, install the node-fetch
package using npm:
Create a JavaScript file called index.js
:
import fetch from "node-fetch"
const url = "https://rpc.testnet.tryradi.us/<YOUR-RPC-ENDPOINT>"
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
method: "eth_blockNumber",
params: [],
id: 1,
}),
})
.then((response) => response.json())
.then((data) => {
console.log(data)
})
.catch((error) => {
console.error(error)
})
Run the code using the following command:
In your project folder, install the axios
package using npm:
Create a JavaScript file called index.js
:
import axios from "axios"
const url = "https://rpc.testnet.tryradi.us/<YOUR-RPC-ENDPOINT>"
axios
.post(url, {
jsonrpc: "2.0",
method: "eth_blockNumber",
params: [],
id: 1,
})
.then((response) => {
console.log(response.data)
})
.catch((error) => {
console.error(error)
})
Run the code using the following command:
In your project folder, install the ethers
package using npm:
Create a JavaScript file called index.js
:
import { ethers } from "ethers"
const url = "https://rpc.testnet.tryradi.us/<YOUR-RPC-ENDPOINT>"
const provider = new ethers.JsonRpcProvider(url)
provider
.getBlockNumber()
.then((blockNumber) => {
console.log(blockNumber)
})
.catch((error) => {
console.error(error)
})
Run the code using the following command:
In your project folder, install the web3
package using npm:
Create a JavaScript file called index.js
:
import { Web3 } from "web3"
const url = "https://rpc.testnet.tryradi.us/<YOUR-RPC-ENDPOINT>"
const provider = new Web3.providers.HttpProvider(url)
const web3 = new Web3(provider)
web3.eth.getBlockNumber().then((blockNumber) => {
console.log(blockNumber)
})
Run the code using the following command: