Skip to content

Instantly share code, notes, and snippets.

@ilyar
Last active October 24, 2022 14:19
Show Gist options
  • Save ilyar/49968703823f8f70ea33efa1d8ed2190 to your computer and use it in GitHub Desktop.
Save ilyar/49968703823f8f70ea33efa1d8ed2190 to your computer and use it in GitHub Desktop.
Use Daedalus socket for cardano-cli via Docker for Mainnet or Testnet the Cardano
#!/usr/bin/env bash
#########################################
# Daedalus Wallet for the Cardano Testnet
# Download https://developers.cardano.org/en/testnets/cardano/get-started/wallet/
# Run Daedalus for Testnet
# Create var CARDANO_NODE_SOCKET_PATH
export CARDANO_NODE_SOCKET_PATH=$(ps ax | grep -v grep | grep cardano-wallet | grep testnet | sed -E 's/(.*)node-socket //')
# Check var it must be path for file of node socket and not empty
echo $CARDANO_NODE_SOCKET_PATH
# Create alias cardano-cli via docker
alias cardano-cli="docker run --rm -it -u $(id -u):$(id -g) -v "$(pwd)":/data -w /data -v "$CARDANO_NODE_SOCKET_PATH":/node.socket -e CARDANO_NODE_SOCKET_PATH=/node.socket --entrypoint cardano-cli inputoutput/cardano-node"
# Check connect if yor run Daedalus for Testnet
cardano-cli get-tip --testnet-magic 1097911063
#########################################
# Daedalus Wallet for the Cardano Mainnet
# Download https://daedaluswallet.io/en/download/
# Run Daedalus for Mainnet
# Create var CARDANO_NODE_SOCKET_PATH
export CARDANO_NODE_SOCKET_PATH=$(ps ax | grep -v grep | grep cardano-wallet | grep mainnet | sed -E 's/(.*)node-socket //')
# Check var it must be path for file of node socket and not empty
echo $CARDANO_NODE_SOCKET_PATH
# Create alias cardano-cli via docker
alias cardano-cli="docker run --rm -it -u $(id -u):$(id -g) -v "$(pwd)":/data -w /data -v "$CARDANO_NODE_SOCKET_PATH":/node.socket -e CARDANO_NODE_SOCKET_PATH=/node.socket --entrypoint cardano-cli inputoutput/cardano-node"
# Check connect if yor run Daedalus for Mainnet
cardano-cli get-tip --mainnet
@ilyar
Copy link
Author

ilyar commented Jun 5, 2021

@rae89 If cardano-cli is bin see https://gist.github.com/ilyar/09eda2bb01545296aa9e1351b8218086#file-use-daedalus-socket-cardano-cli-sh
Or specify exactly how you create the container? You probably need to set up an environment variable.

@leonfs
Copy link

leonfs commented Aug 4, 2021

It didn't work in OSX. The socket get's mounted into the container and I can see it the filesystem when executing ls. Unfortunately, I end up with a cardano-cli: Network.Socket.connect: <socket: 11>: does not exist (Connection refused) error.

@ilyar
Copy link
Author

ilyar commented Aug 4, 2021

@leonfs maybe Daedalus not running

# Check var it must be path for file of node socket and not empty
echo $CARDANO_NODE_SOCKET_PATH

@leonfs
Copy link

leonfs commented Aug 8, 2021

Thanks @ilyar. Unfortunately, is not working. When I use the native cardano-cli, I can connect without problems. The OSX Docker integration might be messing things up.

@ilyar
Copy link
Author

ilyar commented Aug 13, 2021

@leonfs for OSX use sed -E insted sed -r i'm updated script

@leonfs
Copy link

leonfs commented Aug 18, 2021

Thanks for your reply @ilyar. The path to the socket was fine, even before your update to the script. I think the challenge in OSX is all the layers that Docker in Mac adds. I can see the socket file within the container, mounted from the path found by your script. Unfortunately, when trying to connect using the client, the connection always fails. I resolved to use a native OSX binary, using the same socket I was mounting to the Docker container. That worked. Still puzzled about the real cause behind not working with Docker. Maybe, someone one day will add some light to the issue.

cardano-cli: Network.Socket.connect: <socket: 11>: does not exist (Connection refused)%

@xbglowx
Copy link

xbglowx commented Dec 18, 2021

I am running into the same problem.

I believe this is the docker-for-mac issue that was only worked on to get ssh-agent forwarding working.

@uArtApe
Copy link

uArtApe commented Feb 3, 2022

Hi Ilyar,
thanks for the gist, work like a charme. Do you have an idea about correct alias for submit-api (inputoutput/cardano-submit-api)?
I miss something alias cardano-submit-api="docker run -v /data -e NETWORK=mainnet inputoutput/cardano-submit-api"

@ilyar
Copy link
Author

ilyar commented Feb 3, 2022

@uArtApe I haven't had a chance to learn the submit-api (inputoutput/cardano-submit-api) yet

@uArtApe
Copy link

uArtApe commented Feb 3, 2022

Thanks for the reply. As soon as I managed to run it with docker I let you know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment