Skip to content

Commit a9078af

Browse files
authored
Merge pull request #346 from lavanet/add-berachain
Add berachain endpoints
2 parents 451e707 + 7f6dc94 commit a9078af

File tree

6 files changed

+419
-10
lines changed

6 files changed

+419
-10
lines changed

docs/chains/arbitrum-chain/arbitrum-dev.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -235,22 +235,22 @@ To learn more about using the Lava Gateway visit the [Getting Started guide](htt
235235
// npm i @lavanet/lava-sdk
236236
const { LavaSDK } = require("@lavanet/lava-sdk");
237237

238-
async function useEthereumMainnet() {
239-
const ethereumMainnet = await LavaSDK.create({
238+
async function useArbitrumMainnet() {
239+
const arbitrumMainnet = await LavaSDK.create({
240240
privateKey: process.env.PRIVATE_KEY, //hide your private key in an environmental variable
241241
chainIds: "ARB1",
242242
});
243243

244-
const ethereumBlockResponse = await ethereumMainnet.sendRelay({
244+
const arbitrumBlockResponse = await arbitrumMainnet.sendRelay({
245245
method: "eth_blockNumber",
246246
params: [],
247247
});
248248

249-
console.log(ethereumBlockResponse);
249+
console.log(arbitrumBlockResponse);
250250
}
251251

252252
(async () => {
253-
await useEthereumMainnet();
253+
await useArbitrumMainnet();
254254
})();
255255
```
256256

@@ -262,25 +262,25 @@ async function useEthereumMainnet() {
262262
// npm i @lavanet/lava-sdk
263263
const { LavaSDK } = require("@lavanet/lava-sdk");
264264

265-
async function useEthereumMainnet() {
266-
const ethereumMainnet = await LavaSDK.create({
265+
async function useArbitrumMainnet() {
266+
const arbitrumMainnet = await LavaSDK.create({
267267
badge: {
268268
badgeServerAddress: "https://badges.lavanet.xyz", // Or your own Badge-Server URL
269269
projectId: "enter_your_project_id_here",
270270
},
271271
chainIds: "ARB1",
272272
});
273273

274-
const ethereumBlockResponse = await ethereumMainnet.sendRelay({
274+
const arbitrumBlockResponse = await arbitrumMainnet.sendRelay({
275275
method: "eth_blockNumber",
276276
params: [],
277277
});
278278

279-
console.log(ethereumBlockResponse);
279+
console.log(arbitrumBlockResponse);
280280
}
281281

282282
(async () => {
283-
await useEthereumMainnet();
283+
await useArbitrumMainnet();
284284
})();
285285
```
286286

docs/chains/bera-chain/bera-dev.md

+259
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
---
2+
slug: /bera-dev
3+
title: Getting Berachain RPC
4+
---
5+
6+
import Tabs from '@theme/Tabs';
7+
import TabItem from '@theme/TabItem';
8+
9+
# Getting Berachain RPC
10+
11+
## API Reference
12+
13+
<Tabs>
14+
<TabItems value="JSONRPC/HTTP" label="JSONRPC/HTTP">
15+
<Tabs>
16+
<TabItems value="cURL" label="cURL">
17+
18+
```shell
19+
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer e04c14f2-7735-4034-a458-dd1a39e75b39" https://g.w.lavanet.xyz:443/gateway/bera/rpc-http/3dc655f970c930f1d3e78ee71beece18 --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
20+
```
21+
22+
</TabItems>
23+
<TabItems value="Python" label="Python">
24+
25+
```python
26+
# pip install requests
27+
import requests
28+
import json
29+
30+
# URL for the Berachain RPC HTTP endpoint
31+
url = "https://g.w.lavanet.xyz:443/gateway/bera/rpc-http/3dc655f970c930f1d3e78ee71beece18"
32+
# JSON-RPC request payload
33+
request_payload = {
34+
"jsonrpc": "2.0",
35+
"method": "eth_blockNumber",
36+
"params": [],
37+
"id": 1,
38+
}
39+
40+
try:
41+
# HTTP headers
42+
headers = {"Content-Type": "application/json"}
43+
# Sending POST request
44+
response = requests.post(url, headers=headers, data=json.dumps(request_payload))
45+
response.raise_for_status() # Check if the request was successful
46+
# Parsing JSON response
47+
data = response.json()
48+
print("Block Number Response:", data)
49+
except requests.exceptions.RequestException as e:
50+
print(f"Error fetching block number: {e}")
51+
```
52+
53+
</TabItems>
54+
<TabItems value="NodeJS" label="NodeJS">
55+
56+
```jsx
57+
//npm i axios
58+
const axios = require("axios");
59+
60+
// URL for the Berachain RPC HTTP endpoint
61+
const url =
62+
"https://g.w.lavanet.xyz:443/gateway/bera/rpc-http/3dc655f970c930f1d3e78ee71beece18";
63+
// JSON-RPC request payload
64+
const requestPayload = {
65+
jsonrpc: "2.0",
66+
method: "eth_blockNumber",
67+
params: [],
68+
id: 1,
69+
};
70+
71+
async function fetchBlockNumber() {
72+
try {
73+
// Sending POST request
74+
const response = await axios.post(url, requestPayload, {
75+
headers: {
76+
"Content-Type": "application/json",
77+
},
78+
});
79+
// Logging the response
80+
console.log("Block Number Response:", response.data);
81+
} catch (error) {
82+
console.error("Error fetching block number:", error.message);
83+
}
84+
}
85+
86+
fetchBlockNumber();
87+
```
88+
89+
</TabItems>
90+
91+
</Tabs>
92+
</TabItems>
93+
<TabItems value="JSONRPC/WEBSOCKET" label="JSONRPC/WEBSOCKET">
94+
<Tabs>
95+
<TabItems value="WSCAT" label="WSCAT">
96+
97+
```shell
98+
wscat -c wss://g.w.lavanet.xyz:443/gateway/bera/rpc/3dc655f970c930f1d3e78ee71beece18 -x '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
99+
```
100+
101+
102+
</TabItems>
103+
<TabItems value="Python" label="Python">
104+
105+
```python
106+
# pip install asyncio websockets
107+
import asyncio
108+
import websockets
109+
import json
110+
111+
# WebSocket URL and JSON-RPC request payload
112+
url = "wss://g.w.lavanet.xyz:443/gateway/bera/rpc/3dc655f970c930f1d3e78ee71beece18?secret=null"
113+
request_payload = {
114+
"jsonrpc": "2.0",
115+
"method": "eth_blockNumber",
116+
"params": [],
117+
"id": 1,
118+
}
119+
120+
async def fetch_block_number():
121+
try:
122+
async with websockets.connect(url) as websocket:
123+
print("WebSocket connection opened.")
124+
# Send the JSON-RPC request payload
125+
await websocket.send(json.dumps(request_payload))
126+
127+
# Receive the response
128+
response = await websocket.recv()
129+
print("Received response:", response)
130+
except Exception as e:
131+
print("Error:", e)
132+
133+
# Run the async function
134+
asyncio.run(fetch_block_number())
135+
```
136+
137+
</TabItems>
138+
<TabItems value="NodeJS" label="NodeJS">
139+
140+
```jsx
141+
//npm i ws
142+
const WebSocket = require("ws");
143+
144+
// WebSocket URL and JSON-RPC request payload
145+
const url =
146+
"wss://g.w.lavanet.xyz:443/gateway/bera/rpc/3dc655f970c930f1d3e78ee71beece18?secret=null";
147+
const requestPayload = {
148+
jsonrpc: "2.0",
149+
method: "eth_blockNumber",
150+
params: [],
151+
id: 1,
152+
};
153+
154+
const ws = new WebSocket(url);
155+
156+
// Open the WebSocket connection
157+
ws.on("open", () => {
158+
console.log("WebSocket connection opened.");
159+
// Send the JSON-RPC request
160+
ws.send(JSON.stringify(requestPayload));
161+
});
162+
163+
// Listen for the response message
164+
ws.on("message", (message) => {
165+
console.log("Received response:", message.toString());
166+
ws.close();
167+
});
168+
169+
// Handle WebSocket errors
170+
ws.on("error", (error) => {
171+
console.error("WebSocket error:", error.message);
172+
});
173+
174+
// Handle connection closure
175+
ws.on("close", () => {
176+
console.log("WebSocket connection closed.");
177+
});
178+
```
179+
180+
</TabItems>
181+
182+
</Tabs></TabItems>
183+
184+
</Tabs>
185+
186+
<hr/>
187+
188+
## [Gateway](https://gateway.lavanet.xyz)
189+
190+
To learn more about using the Lava Gateway visit the [Getting Started guide](https://docs.lavanet.xyz/gateway-getting-started)
191+
192+
<hr />
193+
<br />
194+
195+
## SDK
196+
197+
### Input 📥
198+
199+
<Tabs>
200+
<TabItem value="backend" label="BackEnd">
201+
202+
```jsx
203+
// Install lavaSDK with the following command:
204+
// npm i @lavanet/lava-sdk
205+
const { LavaSDK } = require("@lavanet/lava-sdk");
206+
207+
async function useBeraMainnet() {
208+
const beraMainnet = await LavaSDK.create({
209+
privateKey: process.env.PRIVATE_KEY, //hide your private key in an environmental variable
210+
chainIds: "BERA",
211+
});
212+
213+
const beraBlockResponse = await beraMainnet.sendRelay({
214+
method: "eth_blockNumber",
215+
params: [],
216+
});
217+
218+
console.log(beraBlockResponse);
219+
}
220+
221+
(async () => {
222+
await useBeraMainnet();
223+
})();
224+
```
225+
226+
</TabItem>
227+
<TabItem value="frontend" label="FrontEnd">
228+
229+
```jsx
230+
// Install lavaSDK with the following command:
231+
// npm i @lavanet/lava-sdk
232+
const { LavaSDK } = require("@lavanet/lava-sdk");
233+
234+
async function useBeraMainnet() {
235+
const beraMainnet = await LavaSDK.create({
236+
badge: {
237+
badgeServerAddress: "https://badges.lavanet.xyz", // Or your own Badge-Server URL
238+
projectId: "enter_your_project_id_here",
239+
},
240+
chainIds: "BERA",
241+
});
242+
243+
const beraBlockResponse = await beraMainnet.sendRelay({
244+
method: "eth_blockNumber",
245+
params: [],
246+
});
247+
248+
console.log(beraBlockResponse);
249+
}
250+
251+
(async () => {
252+
await useBeraMainnet();
253+
})();
254+
```
255+
256+
</TabItem>
257+
</Tabs>
258+
259+
<hr />

docs/chains/bera-chain/bera-node.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
slug: /bera-node
3+
title: Running an Berachain RPC Node
4+
---
5+
6+
# Running a Berachain RPC Node
7+
8+
Follow [the official guide](https://docs.berachain.com/nodes/quickstart#berachain-node-quickstart) on Berachain documentation for running a Berachain Node.
9+
10+
11+
Once your chain is up and running, you are ready to serve RPC!
12+
13+
14+
## Setup your Provider on Lava Network 🌋
15+
16+
So set up your provider on the Lava Network, you can refer to the [provider setup documentation](https://docs.lavanet.xyz/provider-setup). This should provide you with the necessary information to configure and operate your provider node.

0 commit comments

Comments
 (0)