Hello, I’m very new to the cardano ecosystem
I heard that the daedalus is running the full node.
I’m trying to interact with daedalus using python.
How can I interact with daedalus using api? (python package = requests)
What I want to do
- Create wallet
- Check transaction in my wallet
- Send txn
In
they show how a cardano-cli
command line client can interact with the cardano-node
running, while Daedalus is running.
You could give commands to cardano-cli
(and cardano-wallet
and possibly also cardano-hw-cli
) via the subprocess library: subprocess — Subprocess management — Python 3.12.0 documentation
The protocol spoken between the command line tools and the node is not that well documented, unfortunately. I would also be interested in talking to the node directly instead of just going through the command line tools.
An alternative would be blockfrost.io, which does provide an API without you locally running a node – Daedalus or otherwise. They have a Python SDK: GitHub - blockfrost/blockfrost-python: Python 3 SDK for the Blockfrost.io API. and, I think, can do much of what you want.
1 Like
You would need Haskell bindings for Python and also need to wrap everything in a module that can handle marshaling etc. I would recommend calling CLI if you want to host your own node or experiment locally. Blockfrost is the closest thing to an SDK if you don’t mind using a centralized third party solution and also potentially having an additional layer of issues using their API.
Otherwise you are limited to Haskell.
1 Like
I know that it doesn’t exist, but why should it not be possible to implement the same protocol that cardano-cli
is speaking to the node in Python or any other language without doing any Haskell bindings?
1 Like
Having one programming language use code from another always requires some kind of bindings so they can both agree on what represents a string or how to call a function. Some languages are similar enough that it’s trivial (C mixed with C++) some languages are different enough that it becomes complex (Java mixed with C++ requires JNI etc) However Python and Haskell are so wildly different that I wouldn’t even try unless someone was holding a gun to my head.
That said, if I had to call Haskell from Python for some reason the first thing would be to look at those differences and figure out how to map it. I would stumble upon this in about 5 minutes PythonVsHaskell - Python Wiki and from there I would have a path forward by bringing C into the mix as a third party middle ground to make the negotiation easier as that python wiki suggests.
Since Haskell is not native to any operating system GHC actually compiles down to C eventually. There is a concept in many languages called FFI (foreign function interface) that you would need to use. In this way you could choose which Haskell functions you want to be able to call from Python. See also: FFI Introduction - HaskellWiki
Now the other half of the puzzle would be getting Python to call the C function wrappers. These C functions could then call the FFI exported Haskell functions for the API binding. This has been done a million times before so you can use the ctypes package to load the shared library as suggested in the wiki above or various other packages and methods of Python to C including the language Cython made specifically for that purpose.
This makes the Rube Goldberg machine but it would not be very useful in the Cardano context unless you wrapped all the functions you would need. On the plus side I did a quick search and it looks like someone added the FFI exports to the cardano node possibly: Add cardano-node-capi This adds a basic foreign export library for the node. Pro… - input-output-hk/cardano-node@17ff2c7b - Cardano Updates
Looks like the runNode is all you would need to bind to here as it accepts the same arguments as Cardano CLI from the comments in the commit message. I would bet ADA this is what blockfrost does and then they made their own API on top to mask the parameter passing into more logically organized ways.
1 Like
Everyone is super informative, Thankyou a lot!
2 Likes