curl
curl \
-d '{"jsonrpc":"2.0", "method":"eth_blockNumber", "params":[], "id":1}' \
-H "Content-Type: application/json" \
-H "X-RapidAPI-Key:[Your API key]" \
-H "X-RapidAPI-Host: blockchain-http-rpc1.p.rapidapi.com" \
-X POST \
https://blockchain-http-rpc1.p.rapidapi.com/api/polygon/mumbai
web3js integration
import Web3 from "web3";
const provider = new Web3.providers.HttpProvider(
"https://blockchain-http-rpc1.p.rapidapi.com/api/polygon/mumbai",
{
headers: [
{
name: "X-RapidAPI-Key",
value: "[Your API key]",
},
{
name: "X-RapidAPI-Host",
value: "blockchain-http-rpc1.p.rapidapi.com",
},
],
}
);
const web3 = new Web3(provider);
web3.eth.getBlockNumber().then(function (result) {
console.log("[web3.js] Current block number: " + result);
});
ethersjs integration
import Web3 from "web3";
import { ethers } from "ethers";
const web3provider = new Web3.providers.HttpProvider(
"https://blockchain-http-rpc1.p.rapidapi.com/api/polygon/mumbai",
{
headers: [
{
name: "X-RapidAPI-Key",
value: "[Your API key]",
},
{
name: "X-RapidAPI-Host",
value: "blockchain-http-rpc1.p.rapidapi.com",
},
],
}
);
const provider = new ethers.providers.Web3Provider(web3provider);
provider.getBlockNumber().then(function (result) {
console.log("[ethers.js] Current block number: " + result);
});