<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[judicodes]]></title><description><![CDATA[I love to share knowledge as much as I love to learn!]]></description><link>https://judicodes.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 28 Nov 2026 09:45:38 GMT</lastBuildDate><atom:link href="https://judicodes.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to uninstall a cli package entirely from your Mac]]></title><description><![CDATA[Easily remove CLI packages from your Mac with this step-by-step guide on uninstallation and cleanup for a fresh start]]></description><link>https://judicodes.hashnode.dev/how-to-uninstall-a-cli-package-entirely-from-your-mac</link><guid isPermaLink="true">https://judicodes.hashnode.dev/how-to-uninstall-a-cli-package-entirely-from-your-mac</guid><category><![CDATA[cli]]></category><dc:creator><![CDATA[Joshua Nwankwo]]></dc:creator><pubDate>Tue, 25 Mar 2025 16:49:37 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/9SoCnyQmkzI/upload/f62ec31cf275671b737f9cd617022f7d.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I installed zkapp-cli on node 19 using NVM but ran into an EACCESS Permission error while deploying my test project. To fix it, I modified the package code to bypass the request for global installation. However, I still had to use SUDO prefix to execute the CLI commands, which prompted me to learn about file system permission. After fixing that, I uninstalled everything and installed a fresh new node, but the zk command still existed.</p>
<p>So let's say you have a package you want to delete for some reason, in my case, that will be <code>zkapp-cli</code> and I wanted to delete it entirely and install a new one because I messed up the configuration, normally the first thing one would do is to run <code>npm uninstall &lt;package-name&gt;</code> or you can add <code>sudo</code> if you get a permission error just like me.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1678403967713/a0684240-4982-4085-8b6f-d1154f34f12f.png" alt class="image--center mx-auto" /></p>
<p>The above command should fix it in most cases but there are scenarios where you'd have to add the global flag <code>-g</code> to delete it from the global scope then you'll have to run <code>npm uninstall -g &lt;package-name&gt;</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1678404180599/806df531-3289-4fe4-a2b1-378774380a5e.png" alt class="image--center mx-auto" /></p>
<p>Now let's check if it still exists on our global scope by checking the list of all installed packages by running the following command, as you can see my list is empty cause I deleted everything trying to find out where this package was hiding 😫</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1678404249706/2dd6b4cb-a53f-4f24-9b43-36bd919a6c5b.png" alt class="image--center mx-auto" /></p>
<p>Cool right? Nah! If I still run the <code>zk --version</code> command, I still get the version! 😭</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1678404811930/720267f4-2903-4f99-b8e7-36af22db57cb.png" alt class="image--center mx-auto" /></p>
<p>How do we fix this? If you've tried all the methods available on StackOverflow and the rest but none of them worked don't worry I got you. what we need to do is to check exactly where our terminal is getting the package from and then delete it from there, so for that we are going to run the following command <code>which &lt;package-name&gt;</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1678405515193/f40eafd9-31bb-4ad3-a7af-8992ef3eb082.png" alt class="image--center mx-auto" /></p>
<p>Now we're going to see exactly on our computer where our terminal is getting it from now we can go ahead and delete it by navigating to the parent folder of the files we're trying to delete and run the following command <code>rm file-name</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1678406417122/b6557864-0b78-4494-911a-278e8fc96afd.png" alt class="image--center mx-auto" /></p>
<p>Now let’s check again if it still exists</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1678406480730/242a53f8-4be8-4695-9678-10d63237598b.png" alt class="image--center mx-auto" /></p>
<p>Yah!!!🥳🎉 We fixed it! Now you can either install a fresh one or do whatever you want to do.</p>
<p>PS: Also check the folder to see if there are anymore files relating to the package and also ensure to delete it to avoid conflict in the future.</p>
]]></content:encoded></item><item><title><![CDATA[Migrate data from S3 bucket to Sia renterd]]></title><description><![CDATA[In this tutorial, we will explore how to build a web application using Next.js and TypeScript that can migrate files from an AWS bucket to renterd. We will…]]></description><link>https://judicodes.hashnode.dev/migrate-data-from-s3-bucket-to-sia-renterd</link><guid isPermaLink="true">https://judicodes.hashnode.dev/migrate-data-from-s3-bucket-to-sia-renterd</guid><category><![CDATA[Blockchain]]></category><category><![CDATA[AWS]]></category><category><![CDATA[Programming Blogs]]></category><category><![CDATA[S3]]></category><category><![CDATA[Web3]]></category><dc:creator><![CDATA[Joshua Nwankwo]]></dc:creator><pubDate>Fri, 14 Jul 2023 21:28:50 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1689368851014/2b07e14b-00b9-4409-93a2-c2fca08d7ad5.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4 id="heading-harnessing-renterd-typescript-and-nextjs-for-effortless-file-migration-from-aws-bucket-to-sia">Harnessing renterd, TypeScript, and Next.js for Effortless File Migration from AWS Bucket to Sia.</h4>
<h2 id="heading-introduction">Introduction</h2>
<p>In this tutorial, we will explore how to build a web application using Next.js and TypeScript that can migrate files from an AWS bucket to renterd. We will provide a brief introduction to Sia and renterd, followed by step-by-step instructions on building the web app. By the end of this tutorial, you will have a solid understanding of Sia and Sia renterd, and how to migrate files from an AWS bucket to renterd using a web app built with Next.js and TypeScript. We can upload, migrate and delete any file but to keep this tutorial short, we can only preview image files on the browser.</p>
<h2 id="heading-demo">Demo</h2>
<p>We are going to be building something like this <a target="_blank" href="https://miuve-86d636.spheron.app/">SiaMiuve</a> but won't be going into the entire user interface and user experience and that's because we're trying to keep this tutorial as short as possible. I recommend you go through the app before continuing the tutorial, it's totally worth it!</p>
<h2 id="heading-what-is-sia">What is Sia?</h2>
<p>Sia is a decentralized storage platform that leverages blockchain technology to create a secure and efficient storage network. It aims to provide an alternative to traditional cloud storage services by allowing users to store their data on a network of decentralized nodes. Sia's key features include data redundancy, encryption, and micropayments for storage.</p>
<h2 id="heading-what-is-decentralized-storage">What is decentralized storage?</h2>
<p>Decentralized storage refers to a storage model where data is distributed across multiple nodes or computers instead of being stored in a central location. This decentralized approach offers several benefits, such as improved data availability, increased resilience against failures, and enhanced data privacy and security.</p>
<h2 id="heading-what-is-renterd">What is renterd?</h2>
<p>Renterd is the client software of the Sia network that allows users to interact with the Sia storage platform. It provides functionalities to upload, download, and manage files stored on the Sia network. In our case, we will be using renterd to migrate files from an AWS bucket to the Sia network.</p>
<h2 id="heading-building-the-file-migration-web-app">Building the File Migration Web App</h2>
<p><strong>Prerequisites</strong></p>
<ul>
<li><p>Node.js and npm are installed on your machine.</p>
</li>
<li><p>An AWS account to access and migrate files from an AWS bucket.</p>
</li>
<li><p>Basic knowledge of Next.js and TypeScript.</p>
</li>
<li><p>Renterd reachable API address.</p>
</li>
<li><p>A text editor or IDE for coding.</p>
</li>
<li><p>Command Line Interface (CLI) for running commands and scripts.</p>
</li>
<li><p>Upload some image files to your AWS bucket.</p>
</li>
</ul>
<p><strong>Disclaimer</strong></p>
<p>Please do not upload your <code>.env.local</code> file.</p>
<h2 id="heading-step-1-setting-up-the-nextjs-project">Step 1: Setting up the Next.js Project</h2>
<ol>
<li><p>Create a new Next.js project with TypeScript support by running the following command in your terminal:</p>
<pre><code class="lang-plaintext"> npx create-next-app my-file-migration-app --typescript
</code></pre>
</li>
<li><p>Change into the project directory:</p>
<pre><code class="lang-plaintext"> cd my-file-migration-app
</code></pre>
</li>
</ol>
<h2 id="heading-step-2-installing-dependencies">Step 2: Installing Dependencies</h2>
<ol>
<li>Install the AWS SDK for JavaScript:</li>
</ol>
<pre><code class="lang-plaintext">npm install aws-sdk
</code></pre>
<h2 id="heading-step-3-setting-up-aws-credentials">Step 3: Setting up AWS Credentials</h2>
<p>Before accessing your AWS bucket, you need to set up AWS credentials. These credentials will be used by the utility to authenticate and authorize your access to AWS services. Follow the steps below to set up AWS credentials:</p>
<ol>
<li><p>Log in to the AWS Management Console.</p>
</li>
<li><p>Open the IAM (Identity and Access Management) service.</p>
</li>
<li><p>Navigate to "Users" and click on "Add user" to create a new user.</p>
</li>
<li><p>Provide a name for the user and enable programmatic access.</p>
</li>
<li><p>Attach appropriate permissions to the user. For this tutorial, you will need "AmazonS3FullAccess" permission for the user.</p>
</li>
<li><p>Complete the user creation process and make note of the Access Key ID and Secret Access Key.</p>
</li>
<li><p>In your Next.js project, create a file named <code>.env.local</code> in the root directory.</p>
</li>
<li><p>Add the following content to the <code>.env.local</code> file:</p>
</li>
</ol>
<pre><code class="lang-plaintext">AWS_ACCESS_KEY_ID=&lt;your-access-key-id&gt;
AWS_SECRET_ACCESS_KEY=&lt;your-secret-access-key&gt;
</code></pre>
<blockquote>
<p>Replace &lt; your-access-key-id &gt; and &lt; your-secret-access-key &gt; with your actual AWS credentials.</p>
</blockquote>
<h2 id="heading-env-configuration">env configuration</h2>
<p>Navigate into your <code>next.config.js</code> file and add the below env configuration:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> nextConfig = {
  <span class="hljs-attr">env</span>: {
    <span class="hljs-attr">AWS_ACCESS_KEY</span>: process.env.AWS_ACCESS_KEY,
    <span class="hljs-attr">AWS_SECRET_ACCESS_KEY</span>: process.env.AWS_SECRET_ACCESS_KEY,
  },
};
</code></pre>
<h2 id="heading-step-4-create-utils-files">Step 4: Create utils files</h2>
<p>In your Nextjs project, create new files named utils/s3Utils.ts and add the following code to your s3Utils file:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> AWS <span class="hljs-keyword">from</span> <span class="hljs-string">"aws-sdk"</span>;

<span class="hljs-comment">//Configure AWS</span>
AWS.config.update({
  <span class="hljs-attr">accessKeyId</span>: process.env.AWS_ACCESS_KEY,
  <span class="hljs-attr">secretAccessKey</span>: process.env.AWS_SECRET_ACCESS_KEY,
  <span class="hljs-attr">region</span>: <span class="hljs-string">"us-east-1"</span>,
  <span class="hljs-attr">signatureVersion</span>: <span class="hljs-string">"v4"</span>,
});

<span class="hljs-comment">//Initialize S3</span>
<span class="hljs-keyword">const</span> s3 = <span class="hljs-keyword">new</span> AWS.S3();

<span class="hljs-comment">//Handles S3 file deletion</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> handleS3Delete = <span class="hljs-function">(<span class="hljs-params">key: string</span>) =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Deleting file..."</span>);

  <span class="hljs-keyword">const</span> params = {
    <span class="hljs-attr">Bucket</span>: <span class="hljs-string">"YOUR_BUCKET_NAME"</span>,
    <span class="hljs-attr">Key</span>: key,
  };
  s3.deleteObject(params, <span class="hljs-function">(<span class="hljs-params">error</span>) =&gt;</span> {
    <span class="hljs-keyword">if</span> (error) {
      <span class="hljs-built_in">console</span>.error(<span class="hljs-string">"Error deleting file:"</span>, error);
    } <span class="hljs-keyword">else</span> {
      <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"File deleted successfully"</span>);
    }
  });
};

<span class="hljs-comment">//Handles S3 file upload</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> downloadFromS3 = <span class="hljs-keyword">async</span> (): <span class="hljs-built_in">Promise</span>&lt;any[]&gt; =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Downloading..."</span>);
  <span class="hljs-keyword">const</span> params = {
    <span class="hljs-attr">Bucket</span>: <span class="hljs-string">"YOUR_BUCKET_NAME"</span>,
  };

  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve, reject</span>) =&gt;</span> {
    s3.listObjectsV2(params, <span class="hljs-function">(<span class="hljs-params">err, data</span>) =&gt;</span> {
      <span class="hljs-keyword">if</span> (err) {
        <span class="hljs-built_in">console</span>.log(err);
        reject(err);
      } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">const</span> fileKeys: any = data.Contents?.map(<span class="hljs-function">(<span class="hljs-params">file</span>) =&gt;</span> {
          <span class="hljs-keyword">return</span> {
            <span class="hljs-attr">key</span>: file.Key,
            <span class="hljs-comment">//This returns the file url(key) so we are making another request with each key to get the actual file content using a seperate function(convertUrlToFilePath) to make our code cleaner</span>
            <span class="hljs-attr">url</span>: convertUrlToFile(file.Key),
            <span class="hljs-attr">body</span>: file,
          };
        });
        resolve(fileKeys);
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Done Downloading..."</span>);
      }
    });
  });
};

<span class="hljs-comment">//handles S3 file upload</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> uploadToS3 = <span class="hljs-keyword">async</span> (selectedFile: File) =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Uploading..."</span>);

  <span class="hljs-keyword">const</span> s3 = <span class="hljs-keyword">new</span> AWS.S3();
  <span class="hljs-keyword">if</span> (!selectedFile) {
    <span class="hljs-keyword">return</span>;
  }
  <span class="hljs-keyword">try</span> {
    <span class="hljs-keyword">const</span> params = {
      <span class="hljs-attr">Bucket</span>: <span class="hljs-string">"YOUR_BUCKET_NAME"</span>,
      <span class="hljs-attr">Key</span>: <span class="hljs-string">`<span class="hljs-subst">${<span class="hljs-built_in">Date</span>.now()}</span>.<span class="hljs-subst">${selectedFile.name}</span>`</span> || <span class="hljs-string">""</span>,
      <span class="hljs-attr">Body</span>: selectedFile,
    };
    <span class="hljs-keyword">await</span> s3.upload(params).promise();
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Done Uploading!"</span>);
  } <span class="hljs-keyword">catch</span> (err) {
    <span class="hljs-built_in">console</span>.log(err);
  }
};

<span class="hljs-comment">//Gets file content based on the file key</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> convertUrlToFile = <span class="hljs-function">(<span class="hljs-params">key: any</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> params = {
    <span class="hljs-attr">Bucket</span>: <span class="hljs-string">"YOUR_BUCKET_NAME"</span>,
    <span class="hljs-attr">Key</span>: key,
  };
  <span class="hljs-keyword">const</span> signedUrl = s3.getSignedUrl(<span class="hljs-string">"getObject"</span>, params);
  <span class="hljs-keyword">return</span> signedUrl;
};
</code></pre>
<h2 id="heading-constantsts">Constants.ts</h2>
<p>We need to store a few things we are going to use repeatedly in a file where we can access them easily.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> API_ENDPOINT = <span class="hljs-string">`https://renterd-mock.sia.tools/api/worker/objects/`</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> REGISTER_ENDPOINT = <span class="hljs-string">`https://renterd-mock.sia.tools/api/test/register`</span>;
</code></pre>
<ul>
<li>In your Next.js project, create a new file named utils/siaUtil.ts and add the following code to your constants.ts file:</li>
</ul>
<h2 id="heading-in-your-nextjs-project-create-a-new-file-named-utilssiautilsts-add-the-following-code-to-your-siautils-file">In your Next.js project, create a new file named utils/siaUtils.ts add the following code to your siaUtils file:</h2>
<p>Handles user registration because we are going to need to use the token to make every other request to renterd API endpoints for now we are going to store it in our local storage.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { API_ENDPOINT, REGISTER_ENDPOINT } <span class="hljs-keyword">from</span> <span class="hljs-string">"../constants"</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> register = <span class="hljs-keyword">async</span> () =&gt; {
  <span class="hljs-keyword">return</span> fetch(REGISTER_ENDPOINT, {
    <span class="hljs-attr">method</span>: <span class="hljs-string">"POST"</span>,
    <span class="hljs-attr">redirect</span>: <span class="hljs-string">"follow"</span>,
  })
    .then(<span class="hljs-keyword">async</span> (res) =&gt; <span class="hljs-keyword">await</span> res.json())
    .then(<span class="hljs-function">(<span class="hljs-params">result</span>) =&gt;</span> {
      <span class="hljs-built_in">window</span>.localStorage.setItem(<span class="hljs-string">"token"</span>, <span class="hljs-built_in">JSON</span>.stringify(result));
      <span class="hljs-keyword">return</span> result;
    })
    .catch(<span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span> <span class="hljs-built_in">console</span>.log(err));
};
</code></pre>
<p>Simulates user logout by removing registration token from browser's local storage</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> logOut = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">window</span>.localStorage.removeItem(<span class="hljs-string">"token"</span>);
  <span class="hljs-built_in">window</span>.location.reload();
};
</code></pre>
<p>When uploading the file to renderd, if you upload to a base directory like <code>/documents</code> the file gets uploaded successfully, however, if you upload another file to that same directory, it replaces the one that was previously there but we'd like to upload multiple files so we can still fetch all of them instead of the previous one getting replaced, to do that we are going to create a new path name for every file we are uploading and because we are not 100% sure of that all our files have a unique name, we are going to generate a random path name for each file, there are other ways to do this to ensure uniqueness of file name but for this tutorial, we are going to use the inbuilt JavaScript <code>Maths.random()</code> method.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> uploadToRenterd = <span class="hljs-keyword">async</span> (file: File) =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Uploading..."</span>);
  <span class="hljs-keyword">const</span> password = <span class="hljs-built_in">window</span>.localStorage.getItem(<span class="hljs-string">"token"</span>);
  <span class="hljs-keyword">const</span> username = <span class="hljs-string">""</span>;
  <span class="hljs-keyword">const</span> authHeader =
    <span class="hljs-string">"Basic "</span> + btoa(username + <span class="hljs-string">":"</span> + <span class="hljs-built_in">JSON</span>.parse(password <span class="hljs-keyword">as</span> string));
  <span class="hljs-keyword">const</span> path = (<span class="hljs-built_in">Math</span>.random() + <span class="hljs-number">1</span>).toString(<span class="hljs-number">36</span>).substring(<span class="hljs-number">7</span>);

  <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">`<span class="hljs-subst">${API_ENDPOINT}</span>documents/<span class="hljs-subst">${path}</span>`</span>, {
    <span class="hljs-attr">method</span>: <span class="hljs-string">"PUT"</span>,
    <span class="hljs-attr">redirect</span>: <span class="hljs-string">"follow"</span>,
    <span class="hljs-attr">body</span>: file,
    <span class="hljs-attr">headers</span>: {
      <span class="hljs-attr">Authorization</span>: authHeader,
    },
  })
    .then(<span class="hljs-keyword">async</span> (res) =&gt; {
      <span class="hljs-keyword">await</span> res.text();
      <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"File uploaded successfully!"</span>);
    })
    .catch(<span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span> <span class="hljs-built_in">console</span>.log(err));
};
</code></pre>
<p>Because we need to download all the files we have uploaded so that we can probably render them on the screen or for any other purpose, we need to make a <code>GET</code> request to our base directory which in our case is <code>/documents</code>, this will return an array of an object containing names and sizes of the files we've uploaded previously, this is cool but one thing is missing, we want the file contents too, so we can preview them like we need to do in our demo app.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> downloadFromRentred = <span class="hljs-keyword">async</span> () =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Downloading file"</span>);

  <span class="hljs-keyword">const</span> password = <span class="hljs-built_in">window</span>.localStorage.getItem(<span class="hljs-string">"token"</span>);
  <span class="hljs-keyword">const</span> username = <span class="hljs-string">""</span>;

  <span class="hljs-keyword">const</span> authHeader =
    <span class="hljs-string">"Basic "</span> + btoa(username + <span class="hljs-string">":"</span> + <span class="hljs-built_in">JSON</span>.parse(password <span class="hljs-keyword">as</span> string));

  <span class="hljs-keyword">const</span> res = <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">`<span class="hljs-subst">${API_ENDPOINT}</span>documents`</span>, {
    <span class="hljs-attr">method</span>: <span class="hljs-string">"GET"</span>,
    <span class="hljs-attr">headers</span>: {
      <span class="hljs-attr">Accept</span>: <span class="hljs-string">"application/json"</span>,
      <span class="hljs-attr">Authorization</span>: authHeader,
    },
  });
  <span class="hljs-keyword">const</span> newRes = <span class="hljs-keyword">await</span> res.json();

  <span class="hljs-keyword">const</span> urls = <span class="hljs-keyword">await</span> <span class="hljs-built_in">Promise</span>.all(
    newRes.map(<span class="hljs-keyword">async</span> (res: { <span class="hljs-attr">name</span>: string }) =&gt; {
      <span class="hljs-keyword">const</span> url = <span class="hljs-keyword">await</span> getBase64Url(res.name, authHeader);
      <span class="hljs-keyword">return</span> { <span class="hljs-attr">name</span>: res.name, <span class="hljs-attr">url</span>: url };
    })
  );
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Fils downloaded successfully!"</span>);
  <span class="hljs-keyword">return</span> urls;
};
</code></pre>
<p>Here we are getting individual file contents and converting them to base64 so we can render/preview them on the web app.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> getBase64Url = <span class="hljs-function">(<span class="hljs-params">name: string, authHeader: any</span>) =&gt;</span> {
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-keyword">async</span> (resolve, reject) =&gt; {
    <span class="hljs-keyword">const</span> singleResponse = <span class="hljs-keyword">await</span> fetch(
      <span class="hljs-string">`<span class="hljs-subst">${API_ENDPOINT}</span>documents/<span class="hljs-subst">${name}</span>`</span>,
      {
        <span class="hljs-attr">method</span>: <span class="hljs-string">"GET"</span>,
        <span class="hljs-attr">headers</span>: {
          <span class="hljs-attr">Accept</span>: <span class="hljs-string">"application/json"</span>,
          <span class="hljs-attr">Authorization</span>: authHeader,
        },
      }
    );
    <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> singleResponse.blob();
    <span class="hljs-keyword">const</span> blob = <span class="hljs-keyword">new</span> Blob([data], {});
    <span class="hljs-keyword">const</span> reader = <span class="hljs-keyword">new</span> FileReader();
    reader.readAsDataURL(blob);
    reader.onloadend = <span class="hljs-keyword">async</span> () =&gt; {
      resolve(reader.result?.toString());
    };
    reader.onerror = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err</span>) </span>{
      reject(err);
    };
  });
};
</code></pre>
<p>Deletes file from your renterd files directory using the file name</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> handleSiaDelete = <span class="hljs-function">(<span class="hljs-params">key: string</span>) =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"deleteing..."</span>);

  <span class="hljs-keyword">const</span> password = <span class="hljs-built_in">window</span>.localStorage.getItem(<span class="hljs-string">"token"</span>);
  <span class="hljs-keyword">const</span> username = <span class="hljs-string">""</span>;
  <span class="hljs-keyword">const</span> authHeader =
    <span class="hljs-string">"Basic "</span> + btoa(username + <span class="hljs-string">":"</span> + <span class="hljs-built_in">JSON</span>.parse(password <span class="hljs-keyword">as</span> string));
  fetch(<span class="hljs-string">`<span class="hljs-subst">${API_ENDPOINT}</span>documents/<span class="hljs-subst">${key}</span>`</span>, {
    <span class="hljs-attr">method</span>: <span class="hljs-string">"DELETE"</span>,
    <span class="hljs-attr">redirect</span>: <span class="hljs-string">"follow"</span>,
    <span class="hljs-attr">headers</span>: {
      <span class="hljs-attr">Authorization</span>: authHeader,
    },
  })
    .then(<span class="hljs-keyword">async</span> (res) =&gt; {
      <span class="hljs-keyword">await</span> res.text();
    })
    .catch(<span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span> <span class="hljs-built_in">console</span>.log(err));
};
</code></pre>
<h2 id="heading-step-5-create-the-migration-page">Step 5: Create the migration page</h2>
<ol>
<li>Add the following content to the page.tsx file:</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-string">"use client"</span>;

<span class="hljs-keyword">import</span> { useEffect, useState } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> { downloadFromS3 } <span class="hljs-keyword">from</span> <span class="hljs-string">"../../utils/s3Utils"</span>;
<span class="hljs-keyword">import</span> Image <span class="hljs-keyword">from</span> <span class="hljs-string">"next/image"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Migrate</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [fileList, setFileList] = useState&lt;any[]&gt;([]);
  <span class="hljs-built_in">console</span>.log(fileList);

  useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">const</span> getS3files = <span class="hljs-keyword">async</span> () =&gt; {
      <span class="hljs-keyword">const</span> files = <span class="hljs-keyword">await</span> downloadFromS3();
      setFileList(files);
    };
    getS3files();
  }, []);

  <span class="hljs-keyword">const</span> handleMigrate = <span class="hljs-keyword">async</span> (file: string) =&gt; {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Migrating"</span>);
  };

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>File Migration<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
        {fileList.map((file) =&gt; (
          <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{file.key}</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Image</span> <span class="hljs-attr">src</span>=<span class="hljs-string">{file.url}</span> <span class="hljs-attr">height</span>=<span class="hljs-string">{300}</span> <span class="hljs-attr">width</span>=<span class="hljs-string">{300}</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Image from s3"</span> /&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> handleMigrate(file)}&gt;Migrate<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        ))}
      <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}

<span class="hljs-comment">//Modify UI to your taste</span>
</code></pre>
<p>Update your <code>next.config.ts</code> file with the below configuration to be able to view images from our s3 bucket:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">/** <span class="hljs-doctag">@type <span class="hljs-type">{import('next').NextConfig}</span> </span>*/</span>
<span class="hljs-keyword">const</span> nextConfig = {
  <span class="hljs-attr">images</span>: {
    <span class="hljs-attr">domains</span>: [<span class="hljs-string">"s3.amazonaws.com"</span>, <span class="hljs-string">"miuve.s3.amazonaws.com"</span>],
  },
  <span class="hljs-attr">env</span>: {
    <span class="hljs-attr">AWS_ACCESS_KEY</span>: process.env.AWS_ACCESS_KEY,
    <span class="hljs-attr">AWS_SECRET_ACCESS_KEY</span>: process.env.AWS_SECRET_ACCESS_KEY,
  },
};

<span class="hljs-built_in">module</span>.exports = nextConfig;
</code></pre>
<p>Next, we need to do is to create another utils file and write the functions that are going to help us migrate any file from the files we just fetched from s3 to renterd, to do that, create a new file with the name migrate.ts inside our utils folder and add the following codes:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { downloadFromRentred, uploadToRenterd } <span class="hljs-keyword">from</span> <span class="hljs-string">"./siaUtils"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> getFileNameFromUrl = <span class="hljs-function">(<span class="hljs-params">url: any</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> urlParts = url.split(<span class="hljs-string">"/"</span>);
  <span class="hljs-keyword">return</span> urlParts[urlParts.length - <span class="hljs-number">1</span>];
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> createFileFromFileUrl = <span class="hljs-keyword">async</span> (imageUrl: any) =&gt; {
  <span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> fetch(imageUrl);
  <span class="hljs-keyword">const</span> blob = <span class="hljs-keyword">await</span> response.blob();
  <span class="hljs-keyword">const</span> fileName = getFileNameFromUrl(imageUrl);
  <span class="hljs-keyword">const</span> file = <span class="hljs-keyword">new</span> File([blob], fileName, { <span class="hljs-attr">type</span>: blob.type });

  <span class="hljs-keyword">return</span> file;
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> handleMigration = <span class="hljs-function">(<span class="hljs-params">file: any</span>) =&gt;</span> {
  createFileFromFileUrl(file.url)
    .then(<span class="hljs-keyword">async</span> (file) =&gt; {
      <span class="hljs-keyword">await</span> uploadToRenterd(file);
      <span class="hljs-keyword">await</span> downloadFromRentred();
    })
    .catch(<span class="hljs-function">(<span class="hljs-params">error</span>) =&gt;</span> {
      <span class="hljs-built_in">console</span>.error(error);
    });
};
</code></pre>
<p>In the above code example, we have a function name <code>handleMigration</code> which handles the migration of files from s3 to renterd, what we need to migrate is a file and not a file URL but what we are getting from s3 bucket is a file URL so to fix that we introduced another function that helps us create a file object from the file URL, then we also have another function that takes in file URL and then returns filename which we then pass in as the name of the new file object. A summary of what we did is that:</p>
<ul>
<li><p>We got the file name</p>
</li>
<li><p>Create a new file project from the file URL</p>
</li>
<li><p>Upload the file to sia renterd</p>
</li>
<li><p>Then download our sia renterd files so we can see the new file we just migrated from our s3 bucket.</p>
</li>
</ul>
<p>Now we need to go back to our <code>page.tsx</code> and update our handleMigration function:</p>
<pre><code class="lang-javascript"><span class="hljs-string">"use client"</span>;

<span class="hljs-keyword">import</span> { useEffect, useState } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> { downloadFromS3 } <span class="hljs-keyword">from</span> <span class="hljs-string">"../../utils/s3Utils"</span>;
<span class="hljs-keyword">import</span> Image <span class="hljs-keyword">from</span> <span class="hljs-string">"next/image"</span>;
<span class="hljs-keyword">import</span> { handleMigration } <span class="hljs-keyword">from</span> <span class="hljs-string">"../../utils/migrate"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Migrate</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [fileList, setFileList] = useState&lt;any[]&gt;([]);

  useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">const</span> getS3files = <span class="hljs-keyword">async</span> () =&gt; {
      <span class="hljs-keyword">const</span> files = <span class="hljs-keyword">await</span> downloadFromS3();
      setFileList(files);
    };
    getS3files();
  }, []);

  <span class="hljs-keyword">const</span> handleMigrate = <span class="hljs-keyword">async</span> (file: string) =&gt; {
    handleMigration(file);
  };

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>File Migration<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
        {fileList.map((file) =&gt; (
          <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{file.key}</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Image</span>
              <span class="hljs-attr">src</span>=<span class="hljs-string">{file.url.split(</span>"?")[<span class="hljs-attr">0</span>]}
              <span class="hljs-attr">height</span>=<span class="hljs-string">{300}</span>
              <span class="hljs-attr">width</span>=<span class="hljs-string">{300}</span>
              <span class="hljs-attr">alt</span>=<span class="hljs-string">"Image from s3"</span>
            /&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> handleMigrate(file)}&gt;Migrate<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        ))}
      <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}
</code></pre>
<h3 id="heading-test">Test</h3>
<p>Start the Next.js development server by running the following command in your project directory:</p>
<pre><code class="lang-plaintext">npm run dev
</code></pre>
<p>If you click on the migrate button you'll get a <code>401</code> error and that's because we're trying to upload to renterd without our auth token, we've written the function but we've not called it so let's fix that, we need to update our page.tsx to enable us resiter:</p>
<pre><code class="lang-javascript">&lt;button onClick={<span class="hljs-function">() =&gt;</span> register()}&gt;Register&lt;/button&gt;
</code></pre>
<p>Also, remember to import the function at the top of your file</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { register } <span class="hljs-keyword">from</span> <span class="hljs-string">"../../utils/siaUtils"</span>;
</code></pre>
<p>Now let's try to migrate a file again. Firstly, click on the register button and then click on migrate button.</p>
<p>Yeah!🎊 it's working! we just successfully migrated and we are also fetching the file! congratulations!</p>
<p>let's get our app to display our sia file on the screen</p>
<h2 id="heading-bonus">Bonus</h2>
<p>You can also upload files directly to renterd and even delete them, we already have the functions written in our siaUtil file:</p>
<pre><code class="lang-javascript"><span class="hljs-string">"use client"</span>;

<span class="hljs-keyword">import</span> { useEffect, useState } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> { downloadFromS3 } <span class="hljs-keyword">from</span> <span class="hljs-string">"../../utils/s3Utils"</span>;
<span class="hljs-keyword">import</span> Image <span class="hljs-keyword">from</span> <span class="hljs-string">"next/image"</span>;
<span class="hljs-keyword">import</span> { handleMigration } <span class="hljs-keyword">from</span> <span class="hljs-string">"../../utils/migrate"</span>;
<span class="hljs-keyword">import</span> { downloadFromRentred, register } <span class="hljs-keyword">from</span> <span class="hljs-string">"../../utils/siaUtils"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Migrate</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [fileList, setFileList] = useState&lt;any[]&gt;([]);
  <span class="hljs-keyword">const</span> [siafiles, setSiaFiles] = useState&lt;any[]&gt;([]);

  useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">const</span> getS3files = <span class="hljs-keyword">async</span> () =&gt; {
      <span class="hljs-keyword">const</span> files = <span class="hljs-keyword">await</span> downloadFromS3();
      setFileList(files);
      <span class="hljs-keyword">const</span> files2 = <span class="hljs-keyword">await</span> downloadFromRentred();
      setSiaFiles(files2);
    };
    getS3files();
  }, []);

  <span class="hljs-keyword">const</span> handleMigrate = <span class="hljs-keyword">async</span> (file: string) =&gt; {
    handleMigration(file);
  };

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>File Migration<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> register()}&gt;Register<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>S3 files<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
        {fileList.map((file) =&gt; (
          <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{file.key}</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Image</span>
              <span class="hljs-attr">src</span>=<span class="hljs-string">{file.url.split(</span>"?")[<span class="hljs-attr">0</span>]}
              <span class="hljs-attr">height</span>=<span class="hljs-string">{300}</span>
              <span class="hljs-attr">width</span>=<span class="hljs-string">{300}</span>
              <span class="hljs-attr">alt</span>=<span class="hljs-string">"Image from s3"</span>
            /&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> handleMigrate(file)}&gt;Migrate<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        ))}
      <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Sia files<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
        {siafiles.map((file) =&gt; (
          <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{file.name}</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Image</span>
              <span class="hljs-attr">src</span>=<span class="hljs-string">{file.url}</span>
              <span class="hljs-attr">height</span>=<span class="hljs-string">{300}</span>
              <span class="hljs-attr">width</span>=<span class="hljs-string">{300}</span>
              <span class="hljs-attr">alt</span>=<span class="hljs-string">"Image from s3"</span>
            /&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        ))}
      <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}
</code></pre>
<h1 id="heading-summary">Summary</h1>
<p>Now you have your project up and running, here are a few resources to help you learn more about Sia and decentralized storage systems and also join our vibrant community!</p>
<p>You can find the codebase link below and if you have any questions please don't hesitate to reach out to us on Discord!</p>
<p>Demo Project link: <a target="_blank" href="https://miuve-86d636.spheron.app/">https://miuve-86d636.spheron.app/</a></p>
<p>Sia website: <a target="_blank" href="https://sia.tech/">https://sia.tech/</a></p>
<p>Sia Documentation: <a target="_blank" href="https://docs.sia.tech/get-started-with-sia/sia101">https://docs.sia.tech/get-started-with-sia/sia101</a></p>
<p>Sia Community: <a target="_blank" href="https://discord.gg/sia">https://discord.gg/sia</a></p>
<p>Project repo: <a target="_blank" href="https://github.com/joshuanwankwo/sia_file_migration_utility">https://github.com/joshuanwankwo/sia_file_migration_utility</a></p>
]]></content:encoded></item><item><title><![CDATA[EACCES error fix: Everything you need to know]]></title><description><![CDATA[Guide to fixing EACCES error for directory access. Covers permissions, issues, and provides step-by-step solutions with extra tips.]]></description><link>https://judicodes.hashnode.dev/eacces-error-fix-everything-you-need-to-know</link><guid isPermaLink="true">https://judicodes.hashnode.dev/eacces-error-fix-everything-you-need-to-know</guid><category><![CDATA[file-permission]]></category><category><![CDATA[EACCESS-ERROR]]></category><category><![CDATA[permission issues]]></category><dc:creator><![CDATA[Joshua Nwankwo]]></dc:creator><pubDate>Fri, 17 Mar 2023 22:00:31 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1678413575490/933123f1-aae7-4eab-b4ea-eda84bcc7fbe.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hey there! Have you ever come across an EACCESS error while installing a package, editing a file, or accessing a file/directory? It can be pretty frustrating, right? Sometimes adding <code>sudo</code> to your command does the trick, but other times it just doesn't seem to work. I know the feeling because I recently faced a similar issue and it took me a while to figure out what was causing the error and how to fix it. But don't worry, I've got you covered! In this article, I'll be sharing with you exactly what I did to fix the error.</p>
<h3 id="heading-cause-of-the-error">Cause of the error?</h3>
<p>Firstly, we need to understand why we are getting the error in the first place, as the error message state, this is a permission error, we are not able to write to that particular directory</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1678412723853/f5aa499a-9687-457f-aaf7-4714ba7b962b.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-what-is-file-permission">What is file permission?</h3>
<p>For us to understand what is happening, we need to understand file permission and how it works so let's get into that!</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1679015818960/76773c45-4b21-4739-b452-37a0bca53c99.jpeg" alt class="image--center mx-auto" /></p>
<p>File permissions control access and actions on files, crucial for system security and file integrity.</p>
<p>There are three fundamental permissions for every file: read, write, and execute. Read permission enables a user to see the file's contents, write permission lets them modify the file, and execute permission permits them to use the file as a program.</p>
<p>So, there are three types of users that can have different levels of permission for different types of permissions. These are the file owner, the group the file belongs to, and all other users. Easy peasy!</p>
<p>For example, the file owner may have read and write permissions, the group may have only read permission, and all other users may have no permissions at all. This would mean that only the owner of the file can make changes to it, members of the group can view the file but not make changes, and all other users are unable to access the file at all.</p>
<p>Understanding file permissions is an important part of managing your system and keeping your files safe and secure.</p>
<pre><code class="lang-plaintext">| Permissions Description | Octal Value     | File Permissions Set     |
| :---------------------- | :-------------: | -----------------------: |
| No access               |       0         |           ---            |
| Execute                 |       1         |           --x            |
| Write                   |       2         |           -w-            |
| Write and execute       |       3         |           -wx            |
| Read                    |       4         |           r--            |
| Read and execute        |       5         |           r-x            |
| Read and write          |       6         |           rw-            |
| Read, write and execute |       7         |           rwx            |
</code></pre>
<p><em>Source:</em> <a target="_blank" href="https://www.macstadium.com/blog/understanding-file-permissions-on-mac"><em>Macstadium</em></a></p>
<h3 id="heading-solution">Solution</h3>
<p>Now we've learned a bit about file system permission let's now navigate to the path where our package is trying to get installed and find out if we have written permission.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1678412951035/e067c61f-b62c-4d48-999c-385357d8153b.png" alt class="image--center mx-auto" /></p>
<p>As you can see, we don't have permission to write to node_module, now we know the cause of our problem let's go ahead and fix it!</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1678413107301/0731f163-7b95-45b1-b6fe-50518ab4cfce.png" alt class="image--center mx-auto" /></p>
<p>Let's check again if we now have to write access by running the following command</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1678413176777/dd72336c-1683-4e24-84bf-e721096cfc34.png" alt class="image--center mx-auto" /></p>
<p>Cool, now we have permission to write, let's go ahead and put it to test</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1678413249974/d0cfa0ee-b202-499a-98b6-1a9dd0104492.png" alt class="image--center mx-auto" /></p>
<p>As you can see our package is now successfully installed!🎉🥳</p>
<h3 id="heading-summary">Summary</h3>
<blockquote>
<p>This article explains the EACCES error, which is a permission issue that occurs when a user is unable to write to a directory. It provides an overview of file permissions, how to check for permission issues and a step-by-step guide on how to fix the error. Additionally, it offers tips and advice for readers.</p>
</blockquote>
<p>DID YOU KNOW?</p>
<p>Hey, before you leave, I have a cool tip for you! Did you know that you can actually like one article up to 10 times? Why not give it a go and click that like button multiple times 😉. Now you know! Also, I'd love to hear your suggestions on what you want me to write about next. Until next time, take care and peace out!</p>
]]></content:encoded></item><item><title><![CDATA[Exploring the Benefits of Zero-Knowledge Proofs on the Blockchain.]]></title><description><![CDATA[Zero-knowledge proof (ZKP) is a mathematical concept that allows a prover to prove the truth of a statement to a verifier without revealing any other…]]></description><link>https://judicodes.hashnode.dev/exploring-the-benefits-of-zero-knowledge-proofs-on-the-blockchain</link><guid isPermaLink="true">https://judicodes.hashnode.dev/exploring-the-benefits-of-zero-knowledge-proofs-on-the-blockchain</guid><category><![CDATA[Web3]]></category><category><![CDATA[Blockchain]]></category><category><![CDATA[zero-knowledge-proofs]]></category><category><![CDATA[privacy]]></category><category><![CDATA[scalability]]></category><dc:creator><![CDATA[Joshua Nwankwo]]></dc:creator><pubDate>Tue, 31 Jan 2023 23:17:03 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/loExs19kh9s/upload/f8f46ca4ba8703816b4632401b4aac3e.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Before we begin, I'd like to assert that I am not a ZKP expert yet; however, I have been researching ZKPs and their applications and have decided to share what I've learned with you. With that said, let's get started!</p>
<p>Did you know that some <a target="_blank" href="https://ciphertrace.com/">startups</a> claim to de-anonymize Bitcoin and alt-currencies, this means that if someone or a group of people are motivated enough they can trace down your transactions on the blockchain to your real identity and that's a threat to one of blockchain's core promises which is privacy, what does that have to do with zkp? well, before we get into that, let's first understand what zkp is and how it works.</p>
<h2 id="heading-what-is-zkp-and-how-does-it-work"><strong>What is ZKP and how does it work?</strong></h2>
<p>ZKP which stands for zero-knowledge proof is a mathematical concept that enables a prover to prove that statement is true to a verifier without actually revealing any other information other than the statement is true.</p>
<p>Let's Imagine that I'm trying to prove to you that I can unlock your phone without showing you how I'll do it; you give me the phone, I unlock it, and give it back to you so you can verify that the phone is indeed unlocked without knowing how I did it. We can try this on multiple phones, and you can verify that for each one, I was able to unlock this phone without disclosing how I did it.</p>
<p>Another example would be if you're trying to decentralize Uber, that means a lot of user data has to be on-chain because computations like calculating the cost of each ride also have to be on-chain which also enables users to trust your platform right? but, if that's the case then that's a big threat to privacy on the blockchain. This will automatically prevent so many people from adopting your web3 uber, there has to be a way right? to fix this, a lot of people have been researching technologies that can help us solve these challenges and that led to technologies like zkRoll-Ups.</p>
<h2 id="heading-how-does-zkp-rollup-works"><strong>How does ZKP rollup works?</strong></h2>
<p>ZkRoll-Ups are layer two scaling solutions that tend to achieve scalability and privacy on the blockchain by compressing transactions performing computations of-chain and only posting a minimal summary of the transactions on-chain.</p>
<p>However, there have been some arguments around whether ZK Roll-Ups are ZKPs or not since some roll-up operators can see incoming transaction details and choose whether to process it or not, also the Merkle tree hash in some of these roll-ups are being revealed which means that if someone is skilled and motivated enough they can review the data in that particular tree.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674075144336/41a528d2-2679-4dcd-aef1-41409941ffaa.jpeg" alt="https://www.youtube.com/watch?v=AX7eAzfSB6w&amp;t=817s" class="image--center mx-auto" /></p>
<p><a target="_blank" href="https://www.youtube.com/watch?v=AX7eAzfSB6w&amp;t=818s">Image source</a></p>
<h2 id="heading-zkp-innovations"><strong>ZKP innovations</strong></h2>
<p>Some other Technologies are being developed to enable end users to apply ZKP on each transaction before sending it out to the blockchain or even roll-up operators, that way roll-up operators cannot see the data in a particular transaction which will limit the manipulation of transaction ordering.</p>
<p>An example of projects already implementing this is ZCash: According to Wikipedia, <a target="_blank" href="https://z.cash/"><strong>Zcash</strong></a> is a cryptocurrency aimed at using cryptography to provide enhanced privacy for its users compared to other cryptocurrencies such as Bitcoin. Zcash is based on Bitcoin's codebase. It shares many similarities, such as a fixed total supply of 21 million units</p>
<h2 id="heading-zkp-adoption"><strong>ZKP Adoption.</strong></h2>
<p>There are drawbacks affecting the adoption of zero-knowledge proof and as some people will say "Selling ZKP now is like selling a car seat belt in the early 70s" people get that it can revolutionize the entire blockchain industry but they feel like it's still going to taker a long time and are not interested in doing the research and development involved.</p>
<p>Here are a few factors affecting the adoption of ZKP;</p>
<ol>
<li><p><strong>Complexity:</strong> This is very obvious, even at this point, I'm still finding a lot of things very confusing, there are not a lot of very relatable terms used in ZKP's learning materials out there and even the maths behind it is very complex.</p>
</li>
<li><p><strong>Lack of awareness:</strong> Not a lot of people know about ZKP and, to be honest, not a lot of people care about it at the moment.</p>
</li>
<li><p><strong>Lack of learning resources:</strong> There are very few resources on what ZKPs are, what can be done with them, and most importantly, how to build a zkApp.</p>
</li>
<li><p><strong>Practical real-world use cases:</strong> there are so many use cases but very few<br /> projects apply them from concept to production. (e.g ZCASH)</p>
</li>
</ol>
<h3 id="heading-solutions"><strong>Solutions</strong></h3>
<p>Here are some of the solutions that can fix the drawbacks affecting ZKP adoption;</p>
<ol>
<li><p><strong>Privacy by default:</strong> privacy should be embedded into the technology, tools, and methodology that enables us to build on the blockchain.</p>
</li>
<li><p><strong>Educational content:</strong> we should create more Educational content around what ZKPs are, why, and how exactly people can start building zero-knowledge-powered applications(zkApps).</p>
</li>
<li><p><strong>Developer's experience:</strong> better documentation should be written ZKP into our existing dApps and even tools that will enable us to build better and faster zkApps for production.</p>
</li>
</ol>
<p>Building zkDapps can be quite confusing and stressful but not impossible, you don't need to know a lot about cryptography or how to program Circom circuits to get started, as long as you know the fundamentals of typescript you can start building your zkDapp today at <a target="_blank" href="https://docs.minaprotocol.com/">Mina protocol.</a> With the well-structured program (<a target="_blank" href="https://minaprotocol.com/zkignite-cohort1-signup">zkIgnite Cohort 1</a>) for literally anyone interested in ZKP, whether you're a developer, marketer, designer, or anything else. Sign up quickly before registration closes.</p>
<h3 id="heading-conclusion"><strong>Conclusion</strong></h3>
<p>I find zero-knowledge proof very fascinating and I'll be exploring everything around it and will also be sharing my knowledge with you guys as I learn so be sure to follow me to learn more about ZKPs.</p>
<p>Are you also new to this technology? do you have any question or thought on it? please drop in the comment section, if you're already familiar with this technology please also drop your thought or feedback in the comment section let's all learn together.</p>
<p>Until next time, bye!</p>
]]></content:encoded></item></channel></rss>