Cardano-node socket

I got confused with this same error but eventually figured it out, maybe this will help.

When you first run your cardano-node command you specify where the socket will be with --socket-path option. It’ll take your node a bit to run through and replay the blocks, so the node socket actually won’t exist until after it starts syncing blocks. That’s when it creates the node socket, so you have to wait a bit at first.

Then, when you run cardano-cli to query the node, it’ll automatically look for the socket that is in the environment variable CARDANO_NODE_SOCKET_PATH. This should be an absolute path (meaning starting with /) so that no matter what directory you run cardano-cli from it’ll find it. You can figure out what yours is by running echo $CARDANO_NODE_SOCKET_PATH or by running env or printenv if you have it install on your linux box.

If when you run those commands nothing is output or there isn’t a CARDANO_NODE_SOCKET_PATH in the list then you have to set it. You can find the absolute path by going into your cardano/db folder and running pwd for “present working directory.”

Ex.

$ pwd
/home/ada/cardano/db

Then you take that and append the the actual socket file that you specified when starting your cardano-node. You can find it by running ls in your db folder. Most times it’s node.socket.

So then you can export that so that your environment variable is set in your terminal session:

Ex.

$ export CARDANO_NODE_SOCKET_PATH=/home/ada/cardano/db/node.socket

Now rerun the env command and make sure it’s set correctly. Then you can try your cardano-cli command.

NOTE that this only sets your environment variable for THIS terminal window! If you want it to automatically be set when you open a new terminal, then you need to add the export command to your ~/.bashrc file

Ex.

echo 'export CARDANO_NODE_SOCKET_PATH="/home/ada/cardano/db/node.socket"' >> ~/.bashrc

Then when you open new terminal windows it should always be set correctly without you having to worry.

Anyway good luck hope this helps make sense of some of the weird socket not found issues.

1 Like