Getting Starknet RPC
Starknet Public RPCโ
Mainnet ๐โ
Service ๐ | URL ๐ |
---|---|
๐ข json-rpc | https://rpc.starknet.lava.build |
Testnet ๐งชโ
Service ๐ | URL ๐ |
---|---|
๐ข json-rpc | https://rpc.starknet-testnet.lava.build |
API Referenceโ
- REST/HTTP
- cURL
- Python
- NodeJS
curl -X POST -H "Content-Type: application/json" https://g.w.lavanet.xyz:443/gateway/strk/rpc-http/3dc655f970c930f1d3e78ee71beece18 --data '{"jsonrpc":"2.0","method":"starknet_blockNumber","params":[],"id":1}'
# pip install requests
import requests
import json
url = "https://g.w.lavanet.xyz:443/gateway/strk/rpc-http/3dc655f970c930f1d3e78ee71beece18"
request_payload = {
"jsonrpc": "2.0",
"method": "starknet_blockNumber",
"params": [],
"id": 1,
}
try:
headers = {"Content-Type": "application/json"}
response = requests.post(url, headers=headers, data=json.dumps(request_payload))
response.raise_for_status() # Raises an HTTPError if the request was unsuccessful
data = response.json()
print("Block Number Response:", data)
except requests.exceptions.RequestException as e:
print(f"Error fetching block number: {e}")
// npm i axios
const axios = require("axios");
const url =
"https://g.w.lavanet.xyz:443/gateway/strk/rpc-http/3dc655f970c930f1d3e78ee71beece18";
const requestPayload = {
jsonrpc: "2.0",
method: "starknet_blockNumber",
params: [],
id: 1,
};
async function fetchBlockNumber() {
try {
const response = await axios.post(url, requestPayload, {
headers: {
"Content-Type": "application/json",
},
});
console.log("Block Number Response:", response.data);
} catch (error) {
console.error("Error fetching block number:", error.message);
}
}
fetchBlockNumber();
Gatewayโ
To learn more about using the Lava Gateway visit the Getting Started guide
SDKโ
caution
Input ๐ฅโ
- BackEnd
- FrontEnd
// Install lavaSDK with the following command:
// npm i @lavanet/lava-sdk
const { LavaSDK } = require("@lavanet/lava-sdk");
async function useStarknet() {
const starknet = await LavaSDK.create({
privateKey: process.env.PRIVATE_KEY, //hide your private key in an environmental variable
chainIds: "STRK",
});
const starknetBlockResponse = await starknet.sendRelay({
method: "starknet_blockNumber",
params: [],
});
console.log(starknetBlockResponse);
}
(async () => {
await useStarknet();
})();
// Install lavaSDK with the following command:
// npm i @lavanet/lava-sdk
const { LavaSDK } = require("@lavanet/lava-sdk");
async function useStarknet() {
const starknet = await LavaSDK.create({
badge: {
badgeServerAddress: "https://badges.lavanet.xyz", // Or your own Badge-Server URL
projectId: "enter_your_project_id_here",
},
chainIds: "STRK",
geolocation: "2",
});
const starknetBlockResponse = await starknet.sendRelay({
method: "starknet_blockNumber",
params: [],
});
console.log(starknetBlockResponse);
}
(async () => {
await useStarknet();
})();
Output ๐คโ
To learn more about our SDK visit the Getting Started guide