|
| 1 | +--- |
| 2 | +slug: /movement-dev |
| 3 | +title: Getting Movement RPC |
| 4 | +--- |
| 5 | + |
| 6 | +import Tabs from '@theme/Tabs'; |
| 7 | +import TabItem from '@theme/TabItem'; |
| 8 | + |
| 9 | +# Getting Movement 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/movement/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 Movement RPC HTTP endpoint |
| 31 | +url = "https://g.w.lavanet.xyz:443/gateway/movement/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 Movement RPC HTTP endpoint |
| 61 | +const url = |
| 62 | + "https://g.w.lavanet.xyz:443/gateway/movement/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/movement/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/movement/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/movement/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 /> |
0 commit comments