Websocket
For this guide we'll be using JavaScript and the ws library to handle the WebSocket connection.
Connect to SEDA Fast
Once you have your API key you can open a WebSocket connection to SEDA Fast. After establishing the connection, the server sends an authorized message if the API key is valid. You must wait for this message before sending execution or feed requests.
Example code:
const WebSocket = require("ws");
const ws = new WebSocket("wss://fast-ws.mainnet.seda.xyz/ws/v1", {
headers: { Authorization: `Bearer ${process.env.SEDA_FAST_API_KEY}` },
});
ws.on("open", () => console.log("π Connected"));
ws.on("message", (data) => {
const msg = JSON.parse(data.toString());
// Uncomment this line to see the full message
// console.log("π¨", JSON.stringify(msg, null, 2));
if (msg.method === "authorized") {
console.log("β
Authorized");
// Close the connection after receiving the authorized notification
ws.close(1000, "closed by client");
}
if (msg.error) {
console.error("β", msg.error.code, msg.error.message);
}
});
ws.on("error", (e) => console.error("β", e));
ws.on("close", (code, reason) => {
console.log("π Disconnected", code ? `(${code}${reason ? `: ${reason}` : ""})` : "");
});Executing a Single Request
Once the authorisation works it is time to execute an Oracle Program.
Understanding the Response
A successful response includes:
Key fields:
id- The JSON-rpc id of the request.result.data.dataRequest- Details of the Oracle Program execution request (program IDs, inputs, gas limits)result.data.dataResult.result- The hex-encoded final result from the Oracle Programresult.data.dataResult.exitCode- 0 indicates success, non-zero indicates an errorresult.data.dataResult.gasUsed- Total gas consumed during executionresult.data.dataResult.drId- Unique identifier for this data requestresult.data.signature- Cryptographic signature for verificationresult.data.result- Convenient top-level access to the result (same as dataResult.result)
Last updated
Was this helpful?
