<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Srdjan Stankovic</title>
    <description>The latest articles on DEV Community by Srdjan Stankovic (@pyropy).</description>
    <link>https://dev.to/pyropy</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F426841%2Fe7eeecf6-3749-4dd3-b03c-49a4b31a0cdd.jpeg</url>
      <title>DEV Community: Srdjan Stankovic</title>
      <link>https://dev.to/pyropy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pyropy"/>
    <language>en</language>
    <item>
      <title>How to communicate with the cardano node on a remote host</title>
      <dc:creator>Srdjan Stankovic</dc:creator>
      <pubDate>Tue, 31 Aug 2021 10:05:16 +0000</pubDate>
      <link>https://dev.to/pyropy/how-to-communicate-with-the-cardano-node-on-a-remote-host-2pf6</link>
      <guid>https://dev.to/pyropy/how-to-communicate-with-the-cardano-node-on-a-remote-host-2pf6</guid>
      <description>&lt;p&gt;Recently, while working on &lt;a href="https://cardano.blue"&gt;Cardano based NFT Marketplace&lt;/a&gt;, my team and I had to come up with a way for our backend to communicate with the cardano node on a remote host.&lt;/p&gt;

&lt;p&gt;Given that our backend is deployed on AWS Fargate we had two choices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deploy cardano-node on AWS Fargate and somehow share UNIX socket file with our backend&lt;/li&gt;
&lt;li&gt;Somehow expose UNIX socket file via some other protocol&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We first tried to deploy the whole Cardano graphql stack (including cardano node) on AWS Fargate but this caused so much trouble for us so we decided to go try the other option.&lt;br&gt;
While exploring for possible solutions we stumbled upon socat, a utility that lets you expose your UNIX socket via TCP (and much more honestly). If you are interested in finding more about socat here is an excellent &lt;a href="https://www.redhat.com/sysadmin/getting-started-socat"&gt;post&lt;/a&gt; that I have personally used to come up with this solution.&lt;/p&gt;
&lt;h2&gt;
  
  
  Exposing Cardano Node socket over TCP
&lt;/h2&gt;

&lt;p&gt;To expose cardano node UNIX socket file we first need to install the socat package. Installation will depend on your OS and package manager but for most major package manager socat should be available under the same name.&lt;br&gt;
To install socat on Debian host (or any other OS using apt-get package manager) you can simply type:&lt;br&gt;
sudo apt-get update # update packages&lt;br&gt;
sudo apt-get install socat&lt;/p&gt;

&lt;p&gt;Now when we have assured that we have required package (socat), to expose our cardano UNIX node socket path we should run following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;socat TCP-LISTEN:3333,fork,reuseaddr, UNIX-CONNECT:&lt;span class="nv"&gt;$CARDANO_NODE_SOCKET_PATH&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should start socat on localhost and expose our cardano node socket file, whose value is set in the &lt;code&gt;CARDANO_NODE_SOCKET_PATH&lt;/code&gt; environment variable.&lt;br&gt;
In case you don't have this environment variable set, you can do it by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;CARDANO_NODE_SOCKET_PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'/path/to/cardano-node/node.socket'&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are running a cardano node with Docker you can checkout &lt;a href="https://github.com/pyropy/cardano-graphql"&gt;my repo&lt;/a&gt; where I have forked cardano-graphql repository and added a Docker container that exposes cardano node socket file via TCP. It's currently on v4.0.0 of cardano-graphql but I might update if there is enough interest for it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connecting to remote cardano node host via TCP
&lt;/h2&gt;

&lt;p&gt;In order to connect to the cardano node on a remote host, we should run following command (given that we have socat already installed on our machine and exposed node socket on other):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;socat UNIX-LISTEN:/path/to/local/node.socket,fork,reuseaddr,unlink-early, TCP:127.0.0.1:3333
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should replace &lt;code&gt;UNIX-LISTEN&lt;/code&gt; value to some path on our local machine where we're going to hold our &lt;code&gt;node.socket&lt;/code&gt; file, and also replace &lt;code&gt;TCP&lt;/code&gt; value with IP of your remote machine.&lt;br&gt;
If we now set &lt;code&gt;CARDANO_NODE_SOCKET_PATH&lt;/code&gt; to the destination on our local machine we should be able to use cardano cli without running cardano node on our local machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;While we're close to smart contracts on the cardano blockchain we still need a way to communicate with our cardano node over the CLI. Our team at &lt;a href="https://cardano.blue"&gt;Cardano Blue&lt;/a&gt; has taken advantage of cardano-cli and made sure trading NFTs is possible even without smart contracts yet available but once they're out I am sure developing applications like this will be much easier.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
