Ogmios
By CardanoSolutions
This page provides instructions on how to interact with the Cardano Ogmios service offered by Demeter.
Ogmios is a lightweight bridge interface for cardano-node. It provides an HTTP / WebSocket API that enables applications to interact with a local cardano-node via JSON+RPC-2.0. Examples and documentation can be found in the GitHub repository.
Each Demeter cluster provides highly-available, multi-tenant instances of Cardano Ogmios. Connections to these instances are load balanced. Projects can connect to the instance and receive events from ogmios.
Demeter Ogmios access will consume DCUs from your project's wallet.
To enable access in your project, you need to add a Cardano Ogmios Port resource:
Once created, your Cardano Ogmios Port resource will present you with the required information to access the Ogmios instance:
NETWORK-VERSION.ogmios-v1.demeter.run
)KEY.NETWORK-VERSION.ogmios-v1.demeter.run
)dmtr-api-key
: dmtr_ogmios63j21khsjx
)The above value will change for each project depending on your configuration.
You can use a library like websockets
to connect to a Ogmios instance in Python. Here's a basic example:
The key on the host not working with python, please set the key on the header(dmtr-api-key
).
import asyncio
import websockets
import json
async def connect_to_websocket():
host = "wss://mainnet-v5.ogmios-m1.demeter.run"
headers = {
'dmtr-api-key': 'dmtr_ogmiosXXX',
}
async with websockets.connect(host, extra_headers=headers) as websocket:
print(f"Connected to {host}")
event = {
'jsonrpc': '2.0',
'method': 'queryLedgerState/utxo',
'params': {
'addresses': ['addrXXXX']
}
}
await websocket.send(json.dumps(event))
response = await websocket.recv()
print(f"Received from server: {response}")
print("WebSocket connection closed.")
asyncio.get_event_loop().run_until_complete(connect_to_websocket())
In this code, replace host
, and dmtr-api-key
if is necessary
This will connect and send an event to get utxos from an address