### Installing Ogmios Server Executable Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/building.md This command installs the Ogmios server executable using cabal. The parameters `--install-method=copy --overwrite-policy=always` ensures the executable will be copied to a directory in your PATH and that existing files are overwritten. The second line runs the installed Ogmios with the --help flag. ```console $ cabal install ogmios:exe:ogmios --install-method=copy --overwrite-policy=always $ ogmios --help ``` -------------------------------- ### Building Documentation with Hugo Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/building.md This shows how to build the documentation using Hugo. It requires Hugo extended version >= 0.96.0 to be installed. The second command will serve the documentation on localhost:1313. ```console hugo # or, alternatively for a development setup on http://localhost:1313 hugo serve ``` -------------------------------- ### Cloning and Building secp256k1 Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/building.md This series of commands clones, configures, builds, and installs a custom revision of bitcoin-core's secp256k1 library with Schnorr signature support enabled. It uses autoconf and libtool for the build process and installs the library to /usr. ```console git clone https://github.com/bitcoin-core/secp256k1.git cd secp256k1 git reset --hard ac83be33d0956faf6b7f61a60ab524ef7d6a473a ./autogen.sh ./configure --prefix=/usr --enable-module-schnorrsig --enable-experimental make make check sudo make install ``` -------------------------------- ### Installing Dependencies and Building TypeScript Client Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/building.md This command utilizes Yarn to install the necessary dependencies for the TypeScript client and then builds the project. It requires Yarn to be installed. ```console $ yarn && yarn build ``` -------------------------------- ### Cloning and Building BLST Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/building.md These commands clone, build, and install the BLST library for BLS12-381 cryptography. It includes creating a pkg-config file for the library and copying headers and the library itself to /usr/local. ```console git clone https://github.com/supranational/blst cd blst git checkout v0.3.10 ./build.sh cat > libblst.pc << EOF prefix=/usr/local exec_prefix=\${prefix} libdir=\${exec_prefix}/lib includedir=\${prefix}/include Name: libblst Description: Multilingual BLS12-381 signature library URL: https://github.com/supranational/blst Version: 0.3.10 Cflags: -I\${includedir} Libs: -L\${libdir} -lblst EOF sudo cp libblst.pc /usr/local/lib/pkgconfig/ sudo cp bindings/blst_aux.h bindings/blst.h bindings/blst.hpp /usr/local/include/ sudo cp libblst.a /usr/local/lib sudo chmod u=rw,go=r /usr/local/{lib/{libblst.a,pkgconfig/libblst.pc},include/{blst.{h,hpp},blst_aux.h}} ``` -------------------------------- ### Running End-to-End Tests Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/building.md These commands navigate to the TypeScript client directory, install dependencies with Yarn, and then execute the end-to-end tests. A synced node running on the preview network and Ogmios running on port 1337 are prerequisites. ```console $ cd clients/TypeScript $ yarn $ yarn test ``` -------------------------------- ### Start Mainnet Cardano Node and Ogmios Server Source: https://github.com/emurgo/ogmios/blob/master/clients/TypeScript/README.md Starts the Cardano node and Ogmios server for the mainnet network. This is a setup step for interacting with the mainnet. ```console yarn mainnet:up ``` -------------------------------- ### Running Ogmios Server with Cabal Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/building.md This command runs the Ogmios server executable directly using cabal. The `-- --help` argument passes the `--help` flag to the Ogmios executable itself, displaying help information. ```console $ cabal run ogmios:exe:ogmios -- --help ``` -------------------------------- ### Cabal Package Configuration for pcre Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/building.md This snippet shows how to specify extra include and library directories for the `pcre-light` package in `cabal.project.local` on MacOS. This is necessary if `pcre` is installed via Homebrew and its default paths are not recognized. ```cabal package pcre-light extra-include-dirs: /opt/homebrew/opt/pcre/include extra-lib-dirs: /opt/homebrew/opt/pcre/lib ``` -------------------------------- ### Building Ogmios Server with Cabal Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/building.md This snippet shows how to build the Ogmios server executable using cabal. `cabal update` updates the package index, and `cabal build ogmios:exe:ogmios` compiles the executable. This process downloads necessary dependencies if it's the first time being executed. ```console $ cabal update $ cabal build ogmios:exe:ogmios ``` -------------------------------- ### Running Unit Tests with Cabal Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/building.md This command runs all the unit tests for the project using cabal. It compiles and executes the test suites defined in the cabal project. ```console $ cabal test all ``` -------------------------------- ### Updating Git Submodules Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/building.md This command initializes and updates the git submodules of the project. This is required to run the unit tests. ```console $ git submodule update --init ``` -------------------------------- ### Cloning Ogmios Server Repository Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/building.md This command clones the Ogmios repository from GitHub using git. The `--depth 1` flag performs a shallow clone, and the `--recursive` and `--shallow-submodules` flags ensure submodules are initialized and cloned shallowly as well. Following the clone, it changes the current directory to the `server` directory. ```console $ git clone --depth 1 --recursive --shallow-submodules git@github.com:cardanosolutions/ogmios.git $ cd cardano-ogmios/server ``` -------------------------------- ### Starting Ogmios and Cardano node with Docker Compose Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/docker.md This command starts the Ogmios and Cardano node stack using Docker Compose. It assumes a `docker-compose.yml` file exists in the current directory that defines the services. ```console $ docker-compose up ``` -------------------------------- ### Start Testnet Cardano Node and Ogmios Server Source: https://github.com/emurgo/ogmios/blob/master/clients/TypeScript/README.md Starts the Cardano node and Ogmios server for the testnet network. This command sets up the environment needed for testing the Ogmios client against the testnet. ```console yarn testnet:up ``` -------------------------------- ### Metadata No Schema Example - JSON Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/configuring.md This JSON snippet illustrates a metadata example using the "no-schema" format. It shows a simple list of integers represented directly in JSON, which is suitable for compatible CBOR objects. ```json [1, 2, 3] ``` -------------------------------- ### Start Mainnet REPL Source: https://github.com/emurgo/ogmios/blob/master/clients/TypeScript/README.md Starts the REPL (Read-Eval-Print Loop) for interacting with the mainnet Cardano node and Ogmios server. ```console yarn repl:start ``` -------------------------------- ### Start Testnet REPL Source: https://github.com/emurgo/ogmios/blob/master/clients/TypeScript/README.md Starts the REPL (Read-Eval-Print Loop) for interacting with the testnet Cardano node and Ogmios server on a specific port. ```console yarn repl:start --port 1337 ``` -------------------------------- ### Metadata Detailed Schema Example - JSON Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/configuring.md This JSON snippet showcases a metadata example using the "detailed schema" format. It describes the CBOR data structure using a domain-specific language within JSON to represent any binary metadata, particularly those not directly mappable using the no-schema approach. ```json { "list": [ { "int": 1 } , { "int": 2 } , { "int": 3 } ] } ``` -------------------------------- ### Query Ledger State Era Start (JSON) Source: https://github.com/emurgo/ogmios/blob/master/docs/content/mini-protocols/local-state-query.md This JSON snippet shows how to query the start of an Era. ```json { "jsonrpc": "2.0", "method": "queryLedgerState/eraStart" } ``` -------------------------------- ### Cloning Ogmios TypeScript Client Repository Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/building.md This command clones the Ogmios repository from GitHub using git. The `--depth 1` flag performs a shallow clone, and the `--recursive` and `--shallow-submodules` flags ensure submodules are initialized and cloned shallowly as well. Following the clone, it changes the current directory to the `clients/TypeScript` directory. ```console $ git clone --depth 1 --recursive --shallow-submodules git@github.com:cardanosolutions/ogmios.git $ cd cardano-ogmios/clients/TypeScript ``` -------------------------------- ### Main Function with Logging Setup in Haskell Source: https://github.com/emurgo/ogmios/blob/master/server/modules/contra-tracers/README.md The main function sets up the logging environment using `withStdoutTracer` and runs the HTTP and DB applications concurrently, passing the respective tracers to them. It depends on functions like `myHttpApplication` and `myDbApplication` to function correctly. ```haskell main :: IO () main = do withStdoutTracer mempty emptyConfiguration $ \tracers -> do concurrently_ (myHttpApplication (tracerHttp tracers)) (myDbApplication (tracerDb tracers)) ``` -------------------------------- ### Install and Build Packages Source: https://github.com/emurgo/ogmios/blob/master/clients/TypeScript/README.md Installs dependencies and builds the Cardano Ogmios TypeScript client packages using Yarn. This command is essential for setting up the development environment and preparing the packages for testing and distribution. ```console yarn install && \ yarn build ``` -------------------------------- ### Cabal Package Flags Configuration Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/building.md This snippet configures the cabal package `cardano-crypto-praos` to use an external libsodium library with VRF support. This is required if you are running a validator node. It specifies a flag to indicate the usage of the external libsodium-vrf library. ```cabal package cardano-crypto-praos flags: -external-libsodium-vrf ``` -------------------------------- ### Ogmios WebSocket Interaction Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/basics.md This JavaScript code demonstrates how to interact with Ogmios using the WebSocket protocol. It uses the `ws` Node.js package to establish a connection, send a `findIntersection` request, and process the response. It requires the `ws` package to be installed (`npm install ws`). ```javascript const WebSocket = require('ws'); const client = new WebSocket("ws://localhost:1337"); client.once('open', () => { const request = { "jsonrpc": "2.0", "method": "findIntersection", "params": { "points": [ "origin" ] } }; client.send(JSON.stringify(request)); }); client.on('message', function(msg) { const response = JSON.parse(msg); // do something with 'response' }); ``` -------------------------------- ### Installing @cardano-ogmios/schema package Source: https://github.com/emurgo/ogmios/blob/master/clients/TypeScript/packages/schema/README.md This command installs the @cardano-ogmios/schema package using yarn. This package is essential for working with Ogmios schemas in TypeScript projects. ```console yarn add @cardano-ogmios/schema ``` -------------------------------- ### Query Network Start Time (JSON) Source: https://github.com/emurgo/ogmios/blob/master/docs/content/mini-protocols/local-state-query.md This JSON snippet represents a request to query the network's start time. The successful response (not provided) will contain the timestamp representing the start time of the Cardano network. ```json { "jsonrpc": "2.0", "method": "queryNetwork/startTime" } ``` -------------------------------- ### Pkg REPL Source: https://github.com/emurgo/ogmios/blob/master/clients/TypeScript/README.md Starts the REPL in pkg mode. This is likely for packaging or distribution purposes. ```console yarn repl:pkg ``` -------------------------------- ### Running cardano-node-ogmios Docker container Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/docker.md This command starts a Cardano node with an Ogmios server using the `cardanosolutions/cardano-node-ogmios` Docker image. It maps port 1337 for Ogmios, creates a named volume for persisting the Cardano node database, and enables interactive support. ```console $ docker run -it \ --name cardano-node-ogmios \ -p 1337:1337 \ -v cardano-node-ogmios-mainnet-db:/db \ cardanosolutions/cardano-node-ogmios:latest ``` -------------------------------- ### Running Ogmios on preprod with custom port Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/docker.md This command starts Ogmios and Cardano node on the preprod network, listening on port 1338. It uses environment variables to configure the network and port, and sets a project name to isolate data volumes. ```console $ NETWORK=preprod OGMIOS_PORT=1338 docker-compose --project-name cardano-ogmios-preprod up ``` -------------------------------- ### Cloning Ogmios repository for Docker Compose Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/docker.md This command clones the Ogmios repository from GitHub and changes the directory to the cloned repository. This is the first step for utilizing the Docker Compose setup provided in the repository. ```console $ git clone --depth 1 git@github.com:cardanosolutions/ogmios.git $ cd cardano-ogmios ``` -------------------------------- ### Running Ogmios standalone Docker container Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/docker.md This command starts a standalone Ogmios server using the `cardanosolutions/ogmios` Docker image. It requires a running Cardano node with its domain socket available under `./ipc`. It maps port 1337 for Ogmios, mounts the Cardano node's socket, and specifies the node configuration file and host address. ```console $ docker run --rm \ --name ogmios \ -p 1337:1337 \ -v ./ipc:/ipc \ cardanosolutions/ogmios:latest \ --node-socket /ipc/node.socket \ --node-config /config/mainnet/cardano-node/config.json \ --host 0.0.0.0 ``` -------------------------------- ### Ogmios Block Synchronization Example Source: https://github.com/emurgo/ogmios/blob/master/docs/content/mini-protocols/local-chain-sync.md This JavaScript example demonstrates how to connect to an Ogmios WebSocket server, find the intersection with the last Byron block, and then synchronize the first 14 Shelley blocks. It uses the `ws` library for WebSocket communication and sends JSON-RPC requests to the Ogmios server. ```javascript const WebSocket = require('ws'); const client = new WebSocket("ws://localhost:1337"); function rpc(method, params, id) { client.send(JSON.stringify({ jsonrpc: "2.0", method, params, id })); } client.once('open', () => { const lastByronBlock = { slot: 4492799, id: "f8084c61b6a238acec985b59310b6ecec49c0ab8352249afd7268da5cff2a457" }; rpc("findIntersection", { points: [lastByronBlock] }, "find-intersection"); }); client.on('message', function(msg) { const response = JSON.parse(msg); switch (response.id) { case "find-intersection": if (!response.result.intersection) { throw "Whoops? Last Byron block disappeared?" } rpc("nextBlock", {}, 14); break; default: if (response.result.direction === "forward") { console.log(response.result); } if (response.id > 0) { rpc("nextBlock", {}, response.id - 1); } else { client.close(); } break; } }); ``` -------------------------------- ### Example Protocol Parameters Response (JSON) Source: https://github.com/emurgo/ogmios/blob/master/docs/content/mini-protocols/local-state-query.md This JSON excerpt represents a sample response from querying the protocol parameters. It includes details like minimum fees, maximum block sizes, stake pool parameters, Plutus cost models, script execution prices, maximum execution units, value size, collateral percentage and versioning. The keys represent different ledger settings. ```json { "minFeeCoefficient": 44, "minFeeConstant": { "lovelace": 155381 }, "maxBlockBodySize": { "bytes": 90112 }, "maxBlockHeaderSize": { "bytes": 1100 }, "maxTransactionSize": { "bytes": 16384 }, "stakeCredentialDeposit": { "lovelace": 2000000 }, "stakePoolDeposit": { "lovelace": 500000000 }, "stakePoolRetirementEpochBound": 18, "desiredNumberOfStakePools": 500, "stakePoolPledgeInfluence": "3/10", "monetaryExpansion": "3/1000", "treasuryExpansion": "1/5", "minStakePoolCost": { "lovelace": 340000000 }, "minUtxoDepositConstant": 0, "minUtxoDepositCoefficient": 4310, "plutusCostModels": { "plutus:v1": [ 205665, 812, 1, 1, 1000, 571, 0, 1, 1000, 24177, 4, 1, 1000, 32, 117366, 10475, 4, 23000, 100, 23000, 100, 23000, 100, 23000, 100, 23000, 100, 23000, 100, 100, 100, 23000, 100, 19537, 32, 175354, 32, 46417, 4, 221973, 511, 0, 1, 89141, 32, 497525, 14068, 4, 2, 196500, 453240, 220, 0, 1, 1, 1000, 28662, 4, 2, 245000, 216773, 62, 1, 1060367, 12586, 1, 208512, 421, 1, 187000, 1000, 52998, 1, 80436, 32, 43249, 32, 1000, 32, 80556, 1, 57667, 4, 1000, 10, 197145, 156, 1, 197145, 156, 1, 204924, 473, 1, 208896, 511, 1, 52467, 32, 64832 ], "plutus:v2": [ 205665, 812, 1, 1, 1000, 571, 0, 1, 1000, 24177, 4, 1, 1000, 32, 117366, 10475, 4, 23000, 100, 23000, 100, 23000, 100, 23000, 100, 23000, 100, 23000, 100, 100, 100, 23000, 100, 19537, 32, 175354, 32, 46417, 4, 221973, 511, 0, 1, 89141, 32, 497525, 14068, 4, 2, 196500, 453240, 220, 0, 1, 1, 1000, 28662, 4, 2, 245000, 216773, 62, 1, 1060367, 12586, 1, 208512, 421, 1, 187000, 1000, 52998, 1, 80436, 32, 43249, 32, 1000, 32, 80556, 1, 57667, 4, 1000, 10, 197145, 156, 1, 197145, 156, 1, 204924, 473, 1, 208896, 511, 1, 52467, 32, 64832 ] }, "scriptExecutionPrices": { "memory": '577/10000', "cpu": '721/10000000' }, "maxExecutionUnitsPerTransaction": { "memory": 14000000, "cpu": 10000000000 }, "maxExecutionUnitsPerBlock": { "memory": 62000000, "cpu": 20000000000 }, "maxValueSize": { "bytes": 5000 }, "collateralPercentage": 150, "maxCollateralInputs": 3, "version": { "major": 8, "minor": 0 } } ``` -------------------------------- ### JSON-WSP Request Example Source: https://github.com/emurgo/ogmios/blob/master/architectural-decisions/accepted/017-api-version-6-major-rewrite.md Illustrates the old JSON-WSP request format used in previous versions of Ogmios for querying information. ```json { "type": "jsonwsp/request", "version": "1.0", "servicename": "ogmios", "methodname": "query", "args": { "query": "genesisConfig" }, "mirror": { "id": "foo" } } ``` -------------------------------- ### Example Network Tip Response (JSON) Source: https://github.com/emurgo/ogmios/blob/master/docs/content/mini-protocols/local-state-query.md This JSON snippet shows the response from querying the network tip. It includes the block hash and slot number of the latest block on the chain. The 'method' field specifies the query that was executed. ```json { "jsonrpc": "2.0", "method": "queryNetwork/tip", "result": { "tip": { "hash": "dbafebb0146b2ec45186dfba6c287ad69c83d3fd9a186b39d99ab955631539e0", "slot": 12526684 } }, "id": "get-network-tip" } ``` -------------------------------- ### Ogmios Block Synchronization Alternate Example Source: https://github.com/emurgo/ogmios/blob/master/docs/content/mini-protocols/local-chain-sync.md This JavaScript example demonstrates an alternative approach to fetching blocks from Ogmios after finding the intersection point. Instead of waiting for replies to send requests, it sends all `nextBlock` requests in a loop after a successful intersection. This allows to collect all responses asynchronously. ```javascript switch (response.id) { case "find-intersection": if (!response.result.intersection) { throw "Whoops? Last Byron block disappeared?" } for (let i = 14; i > 0; i += 1) { rpc("nextBlock"); } break; ... } ``` -------------------------------- ### Local-State Query Response Example Source: https://github.com/emurgo/ogmios/blob/master/architectural-decisions/accepted/017-api-version-6-major-rewrite.md Demonstrates the response format for local-state queries in Ogmios' new API, showing how results are linked to their parent queries and includes the chain tip's slot and id. ```json { "jsonrpc": "2.0", "method": "queryLedgerState/tip", "result": { "slot": 1234, "id": "1234567890abcdef" } } ``` -------------------------------- ### Query Network Tip (JSON) Source: https://github.com/emurgo/ogmios/blob/master/docs/content/mini-protocols/local-state-query.md This JSON snippet exemplifies how to query the network tip, similar to a previous example. It shows the format of the RPC request. The subsequent response would contain the hash and slot of the chain tip. ```json { "jsonrpc": "2.0", "method": "queryNetwork/tip" } ``` -------------------------------- ### Fetching Prometheus Metrics via Curl Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/monitoring.md This command retrieves Prometheus metrics from the `/metrics` endpoint of the Ogmios server. It requires `curl` to be installed. The output is in Prometheus exposition format, which can be scraped by a Prometheus server for monitoring and alerting. ```console $ curl http://localhost:1337/metrics ``` -------------------------------- ### Local-State Query Request Example Source: https://github.com/emurgo/ogmios/blob/master/architectural-decisions/accepted/017-api-version-6-major-rewrite.md Illustrates a local-state query request in the updated Ogmios API using the JSON-RPC 2.0 format to query the chain tip. ```json { "jsonrpc": "2.0", "method": "queryLedgerState/tip", } ``` -------------------------------- ### Submitting Transaction Example (JavaScript) Source: https://github.com/emurgo/ogmios/blob/master/docs/content/mini-protocols/local-tx-submission.md This JavaScript code snippet demonstrates how to submit a Cardano transaction to Ogmios using a WebSocket connection. It includes setting up the WebSocket, constructing the JSON-RPC message, sending the transaction, and handling the response. ```JavaScript const WebSocket = require('ws'); const client = new WebSocket("ws://localhost:1337"); function rpc(method, params) { client.send(JSON.stringify({ jsonrpc: "2.0", method, params })); } client.once('open', () => { const cbor = "83a4008182582000000000000000000000000000000000000000000000000000"+ "0000000000000000018282583901010101010101010101010101010101010101"+ "0101010101010101010101010101010101010101010101010101010101010101"+ "0101010101011a001e8480825839010202020202020202020202020202020202"+ "0202020202020202020202020202020202020202020202020202020202020202"+ "020202020202021a0078175c021a0001faa403191e46a1008182582001000000"+ "000000000000000000000000000000000000000000000000000000005840d7af"+ "60ae33d2af351411c1445c79590526990bfa73cbb3732b54ef322daa142e6884"+ "023410f8be3c16e9bd52076f2bb36bf38dfe034a9f04658e9f56197ab80ff6"; rpc("submitTransaction", { transaction: { cbor } }); }); client.on('message', function(msg) { const response = JSON.parse(msg); console.log(response); client.close(); }); ``` -------------------------------- ### Mempool Monitoring Example - JavaScript Source: https://github.com/emurgo/ogmios/blob/master/docs/content/mini-protocols/local-tx-monitor.md This JavaScript code demonstrates how to use the Ogmios mempool monitoring protocol with a WebSocket connection. It establishes a connection, acquires a mempool snapshot, and then repeatedly requests the next transaction. If a transaction is received, it logs the transaction details. If the result transaction is null, it re-acquires the mempool snapshot. It uses the 'ws' library. Dependencies: ws ```javascript const WebSocket = require('ws'); const client = new WebSocket("ws://localhost:1337"); // Helper function function rpc(method, params) { client.send(JSON.stringify({ jsonrpc: '2.0', method, params })); } client.on('message', e => { const message = JSON.parse(e); if (message?.result?.transaction === null) { rpc('acquireMempool'); } else { console.log(message.result); // Returns transaction id rpc('nextTransaction'); // Returns all transaction information // rpc("nextTransaction", { fields: "all" }); } }); client.once('open', () => { rpc('acquireMempool'); }); ``` -------------------------------- ### Example Stake Distribution Response (JSON) Source: https://github.com/emurgo/ogmios/blob/master/docs/content/mini-protocols/local-state-query.md This JSON is a truncated example of the stake distribution across various stake pools. Each pool is identified by its pool ID, and the corresponding stake and VRF (Verifiable Random Function) values are provided. The stake represents the amount of stake delegated to that pool. ```json { "jsonrpc": "2.0", "method": "queryLedgerState/liveStakeDistribution", "result": { "liveStakeDistribution": { "pool1w3s6gk83y2g3670emy3yfjw9myz3u4whph7peah653rmsfegyj3": { "stake": 0, "vrf": "29c1a293c550beea756bc0c01416bacd7030ae8992e13ca242d4d6c2aebaac0d" }, "pool1n5shd9xdt4s2gm27fxcnuejaqhhmpepn6chw2c82kqnuzdtpsem": { "stake": 0.00003058882418046271, "vrf": "7e363eb8bfd8fef018da4c397d6a6ec25998363434e92276e40ee6c706da3ae5" }, "..." } } } ``` -------------------------------- ### Querying Ledger Epoch Source: https://github.com/emurgo/ogmios/blob/master/docs/content/mini-protocols/local-state-query.md This example demonstrates how to query the current epoch of the ledger using the `queryLedgerState/epoch` method. No parameters are required. The response will contain information about the current epoch. This is an example of a ledger-state query, which is era-dependent. ```json { "jsonrpc": "2.0", "method": "queryLedgerState/epoch", } ``` -------------------------------- ### JSON-RPC Request Example Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/basics.md This JSON snippet demonstrates a valid JSON-RPC request message sent to Ogmios. It uses the `findIntersection` method, which is related to the chain synchronization protocol. The `params` field specifies a list of points for intersection, and the `id` field is used for tracking state. ```json { "jsonrpc": "2.0", "method": "findIntersection", "params": { "points": [ "origin" ] }, "id": "init-1234-5678" } ``` -------------------------------- ### Example Acquire Ledger State Response (JSON) Source: https://github.com/emurgo/ogmios/blob/master/docs/content/mini-protocols/local-state-query.md This JSON displays a successful response from acquiring the ledger state using a specific point (tip). It confirms that the ledger state was acquired and provides details about the acquired point, including its ID (hash) and slot number. The 'method' field indicates the type of query. ```json { "jsonrpc": "2.0", "method": "acquireLedgerState", "result": { "acquired": "ledgerState", "point": { "id": "dbafebb0146b2ec45186dfba6c287ad69c83d3fd9a186b39d99ab955631539e0", "slot": 12526684 } }, "id": "acquire-network-tip" } ``` -------------------------------- ### JSON-RPC Response Example Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/basics.md This JSON snippet shows a possible response to the `findIntersection` request. It contains the same `method` and `id` as the original request. The `result` field provides the intersection point and the tip of the chain, including the block ID, block number, and slot. ```json { "jsonrpc": "2.0", "method": "findIntersection", "result": { "intersection": "origin", "tip": { "id": "d184f428159290bf3558b4d1d139e6a07ec6589738c28a0925a7ab776bde4d62", "blockNo": 4870185, "slot": 12176171 } }, "id": "init-1234-5678" } ``` -------------------------------- ### Querying Health Endpoint via Curl Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/monitoring.md This command retrieves real-time information about the running Ogmios server from the `/health` endpoint, including runtime metrics, connection status, and network synchronization. It requires `curl` to be installed. The output is a JSON object containing various metrics and status information. ```console $ curl -H 'Accept: application/json' http://localhost:1337/health ``` -------------------------------- ### JSON-RPC 2.0 Request Example Source: https://github.com/emurgo/ogmios/blob/master/architectural-decisions/accepted/017-api-version-6-major-rewrite.md Demonstrates the new JSON-RPC 2.0 request format adopted in Ogmios API version 6, providing a more lightweight and standardized approach. ```json { "jsonrpc": "2.0", "method": "queryNetwork/genesisConfiguration", "params": { "era": "shelley" }, "id": "foo" } ``` -------------------------------- ### Native Script 'StartsAt' Clause Transformation (Old) Source: https://github.com/emurgo/ogmios/blob/master/architectural-decisions/accepted/017-api-version-6-major-rewrite.md This JSON snippet represents the old format for a native script start clause. It contains a "startsAt" field containing a slot number. ```json { "startsAt": "" } ``` -------------------------------- ### Example Haskell Data Types with ToJSONViaShow Derivation Source: https://github.com/emurgo/ogmios/blob/master/server/modules/json-via-show/README.md This snippet defines three Haskell data types: `Foo`, `Log`, and `LastUpdate`. Each type derives `Show` using `deriving stock Show` and `ToJSON` using `deriving ToJSON via ToJSONViaShow`. This allows automatic generation of JSON instances based on the `Show` instance. `UTCTime` is used in LastUpdate. ```Haskell {-# LANGUAGE DerivingVia #-} data Foo = Foo { foo :: [Int] , bar :: String } deriving stock Show deriving ToJSON via ToJSONViaShow Foo data Log = Log Bool LastUpdate deriving stock Show deriving ToJSON via ToJSONViaShow Log newtype LastUpdate = LastUpdate { unLastUpdate :: UTCTime } deriving stock Show deriving ToJSON via ToJSONViaShow LastUpdate ``` -------------------------------- ### Native Script 'After' Clause Transformation (New) Source: https://github.com/emurgo/ogmios/blob/master/architectural-decisions/accepted/017-api-version-6-major-rewrite.md This JSON snippet represents the new format for a native script start clause (previously 'startsAt'). It includes a "clause" field set to "after" and a "slot" field containing a slot number. ```json { "clause": "after", "slot": "" } ``` -------------------------------- ### Query Ledger State Constitution (JSON) Source: https://github.com/emurgo/ogmios/blob/master/docs/content/mini-protocols/local-state-query.md This JSON snippet represents an example query for the Ledger State Constitution and its expected response. It showcases the structure of both the request and the successful response, revealing the metadata associated with the constitution, including URL and hash information. ```json { "jsonrpc": "2.0", "method": "queryLedgerState/constitution", "result": { "metadata": { "url": "", "hash": "0000000000000000000000000000000000000000000000000000000000000000" }, "guardrails": null }, "id": null } ``` -------------------------------- ### Ogmios Top-Level Modules Structure - Haskell Source: https://github.com/emurgo/ogmios/blob/master/server/README.md This code snippet represents the top-level module structure of the Ogmios application. It includes modules for application entrypoint (Ogmios.hs), option parsing (Options.hs), custom prelude (Prelude.hs), and version information (Version.hs). These modules are responsible for stitching together the application's various parts and exposing a high-level interface for building the executable. ```tree ^ ─── Ogmios.hs |     ├── Options.hs Application | ├── Prelude.hs v └── Version.hs ``` -------------------------------- ### Query Network Tip and Stake Distribution with Ogmios (JavaScript) Source: https://github.com/emurgo/ogmios/blob/master/docs/content/mini-protocols/local-state-query.md This code snippet demonstrates querying the network tip and then, using the tip information, acquiring the ledger state to subsequently query the live stake distribution across all stake pools. It uses WebSockets to communicate with the Ogmios interface and handles different response methods using a switch statement. It depends on the 'ws' package. ```javascript const WebSocket = require('ws'); const client = new WebSocket("ws://localhost:1337"); function rpc(method, params = {}, id) { client.send(JSON.stringify({ jsonrpc: "2.0", method, params, id })); } client.once('open', () => { rpc("queryNetwork/tip", {}) }); client.on('message', function(msg) { const response = JSON.parse(msg); switch (response.method) { case "queryNetwork/tip": const point = response.result; rpc("acquireLedgerState", { point }); break; case "acquireLedgerState": rpc("queryLedgerState/liveStakeDistribution"); break; default: console.log(response.result); client.close(); break; } }); ``` -------------------------------- ### Run Tests Source: https://github.com/emurgo/ogmios/blob/master/clients/TypeScript/README.md Runs the tests for the Cardano Ogmios TypeScript client packages. This requires a testnet environment to be running. ```console yarn testnet:up ``` ```console yarn test ``` -------------------------------- ### Querying Ledger Tip from Ogmios using JavaScript Source: https://github.com/emurgo/ogmios/blob/master/clients/TypeScript/packages/repl/README.md This JavaScript snippet shows how to query the ledger tip from an Ogmios server. The `ledgerTip()` function available in the REPL returns an object containing the ID and slot of the latest block. This provides information about the current state of the blockchain. ```js ogmios> await ledgerTip() { id: '41364e89e44370a009f083ce9963261aabf6138db519b039012232bf40f187f8', slot: 25541023 } ``` -------------------------------- ### Setting Default Tracer Configuration in Haskell Source: https://github.com/emurgo/ogmios/blob/master/server/modules/contra-tracers/README.md Defines a default configuration for the tracers, setting the minimum severity level to `Info` for all tracers. This can be loaded from config files or CLI parameters in practice. ```haskell emptyConfiguration :: Tracers m MinSeverities emptyConfiguration = defaultTracers Info ``` -------------------------------- ### Pipelining `nextBlock` requests with JavaScript Source: https://github.com/emurgo/ogmios/blob/master/docs/content/mini-protocols/local-chain-sync.md This JavaScript code demonstrates how to pipeline `nextBlock` requests to Ogmios using a WebSocket connection. It bursts the server's queue with multiple requests initially and then sends a new request immediately after receiving each response, optimizing bandwidth utilization. ```javascript const nextBlock = JSON.stringify({ "jsonrpc": "2.0", "method": "nextBlock", }); client.on('open', () => { // Burst the server's queue with a few requests. for (let i = 0; i < 100; i += 1) { client.send(nextBlock); } }); client.on('message', msg => { client.send(nextBlock); // Ask for next request immediately doSomething(msg); }) ``` -------------------------------- ### Query Ledger State Constitutional Committee (JSON) Source: https://github.com/emurgo/ogmios/blob/master/docs/content/mini-protocols/local-state-query.md This JSON snippet presents an example query for the Constitutional Committee and its corresponding response format. It demonstrates the data structure containing the members of the committee, including their IDs, delegate status, and mandate information. The quorum requirement is also specified. ```json { "jsonrpc": "2.0", "method": "queryLedgerState/constitutionalCommittee", "result": { "members": [ { "id": "5f1b4429fe3bda963a7b70ab81135112a785afcf55ccd695b122e794", "delegate": { "status": "authorized", "credential": "5aa349227e4068c85c03400396bcea13c7fd57d0ec78c604bc768fc5" }, "status": "active", "mandate": { "epoch": 379 } }, { "id": "9393c87a66b1f7dd4f9b486a49232de92e39e18b3b20ac4a539b4df2", "delegate": { "status": "authorized", "credential": "670994283668cea40218e0ef33c51aff39ca00a74f68ed428cf305ce" }, "status": "active", "mandate": { "epoch": 379 } }, { "id": "b7bfc26ddc6718133a204af6872149b69de83dd3350f60b257e55773", "delegate": { "status": "none" }, "status": "active", "mandate": { "epoch": 379 } } ], "quorum": "2/3" }, "id": null } ``` -------------------------------- ### Querying Reward Account Summaries by Keys Source: https://github.com/emurgo/ogmios/blob/master/docs/content/mini-protocols/local-state-query.md This JSON snippet demonstrates how to query reward account summaries using a list of keys in Ogmios. It sends a `queryLedgerState/rewardAccountSummaries` request. The `params` object contains a `keys` array with stake key hashes and stake addresses. The server returns reward account summaries for the specified keys. ```JSON { "jsonrpc": "2.0", "method": "queryLedgerState/rewardAccountSummaries", "params": { "keys": [ "7c16240714ea0e12b41a914f2945784ac494bb19573f0ca61a08afa8", "stake_vkh10stzgpc5ag8p9dq6j98jj3tcftzffwce2ulsefs6pzh6s39tk6l" ] } } ``` -------------------------------- ### Ogmios HTTP Request Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/basics.md This JavaScript code shows how to send a request to Ogmios over HTTP using the `fetch` API. It sends a `submitTransaction` request with a transaction payload. It requires the `fetch` API to be available (e.g., via `node-fetch` in Node.js, or built-in in browsers). ```javascript const fetch = require('fetch'); fetch("http://localhost:1337", { method: "POST", data: { "jsonrpc": "2.0", "method": "submitTransaction", "params": { "transaction": "..." } } }).then(async response => { const json = await response.json(); // do something with 'response' }); ``` -------------------------------- ### Evaluate Transaction Execution Units Function Signature - Haskell Source: https://github.com/emurgo/ogmios/blob/master/architectural-decisions/accepted/015-script-execution-units-evaluator.md This Haskell function signature from `cardano-ledger` shows how to evaluate transaction execution units, taking protocol parameters, a transaction, UTxO set, epoch information, system start, and cost models as input. It returns either a basic failure or a redeemer report, encapsulated in a monadic context `m`. ```Haskell evaluateTransactionExecutionUnits :: Core.PParams (AlonzoEra c) -> Core.Tx (AlonzoEra c) -> UTxO (AlonzoEra c) -> EpochInfo m -> SystemStart -> Array Language CostModel -> m (Either (BasicFailure c) (RedeemerReport c)) ``` -------------------------------- ### Lint Code Source: https://github.com/emurgo/ogmios/blob/master/clients/TypeScript/README.md Runs the linter to check the code for style and potential errors. ```console yarn lint ``` -------------------------------- ### Prometheus Metrics Output Source: https://github.com/emurgo/ogmios/blob/master/docs/content/getting-started/monitoring.md This snippet shows the Prometheus metrics exposed by Ogmios. The metrics include information about active connections, CPU time, heap size, network synchronization, session durations, tip information, and total counts of connections, messages, and unrouted messages. The `ogmios_connected` metric indicates the connection status, where 1 means connected and 0 means disconnected. ```bash # TYPE ogmios_active_connections gauge ogmios_active_connections 0.0 # TYPE ogmios_connected gauge ogmios_connected 1.0 # TYPE ogmios_cpu_time counter ogmios_cpu_time 3841629783 # TYPE ogmios_current_epoch counter ogmios_current_epoch 363 # TYPE ogmios_current_heap_size gauge ogmios_current_heap_size 390.0 # TYPE ogmios_gc_cpu_time counter ogmios_gc_cpu_time 3142668337 # TYPE ogmios_max_heap_size gauge ogmios_max_heap_size 433.0 # TYPE ogmios_network_synchronization gauge ogmios_network_synchronization 0.99999 # TYPE ogmios_session_duration_max gauge ogmios_session_duration_max 0.0 # TYPE ogmios_session_duration_mean gauge ogmios_session_duration_mean 0.0 # TYPE ogmios_session_duration_min gauge ogmios_session_duration_min 0.0 # TYPE ogmios_slot_in_epoch counter ogmios_slot_in_epoch 150361 # TYPE ogmios_tip_block counter ogmios_tip_block 7756720 # TYPE ogmios_tip_slot counter ogmios_tip_slot 71603161 # TYPE ogmios_total_connections counter ogmios_total_connections 0 # TYPE ogmios_total_messages counter ogmios_total_messages 0 # TYPE ogmios_total_unrouted counter ogmios_total_unrouted 0 ```