Spheron CLI: Your Gateway to Seamless Dapp Creation and Deployment...

Degen HODLerDegen HODLer
3 min read

Decentralized applications, or dapps, have gained significant attention in the world of blockchain technology. Spheron CLI is a powerful Command Line Interface (CLI) tool that simplifies the process of creating and deploying dapps to the web3 ecosystem.

Prerequisites: Before we begin, ensure that you have the following prerequisites:

  1. Node.js and npm (Node Package Manager) installed on your system.

  2. Basic understanding of JavaScript and Solidity.

  3. Familiarity with command-line tools.

Install Spheron CLI :-

The first step is to install Spheron CLI globally on your system. Open your terminal/command prompt and run the following command:

For Mac and Linux :

sudo npm install -g @spheron/cli

For Windows :

npm install -g @spheron/cli

Now, The --help argument allows you to get more details about Spheron CLI commands.

Step-by-Step Guide: Creating a Dapp to Run on Spheron Out of the Box

First login into your spheron account using following CLI command :

spheron login

Do the following steps

Step 1 : Create a New Spheron Project

Navigate to the directory where you want to create your dapp project. Run the following command to initialize a new Spheron project:

spheron init --protocol {protocol} [--project {project_name}] [--path {path}] [--framework {framework}]

Arguments

  • --protocol : Choose from arweave, filecoin, or ipfs.

  • --project (Optional) : The name of the project. If not provided, the last segment of the path will be taken.

  • --path (Optional) : The location of dir/file that you want to upload. The default path is ./.

  • --framework (Optional) : some of the frameworks supported by spheron :

    static,react,vue,angular,etc..

Step 2: Write Smart Contract Code

Inside the "contracts" folder of your project directory, create a Solidity file (e.g., "MyContract.sol") and define your smart contract code. For example:

pragma solidity ^0.8.0;

contract MyContract {
    // Your contract code here
}

Save the file when you are done.

Step 3: Write Dapp Frontend Code

In the root directory of your project, create an HTML file (e.g., "index.html") and a JavaScript file (e.g., "app.js") to build the dapp frontend. In "index.html," include the necessary dependencies, and in "app.js," write the logic to interact with your smart contract. For example:

<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
    <title>My Dapp</title>
    <!-- Include necessary dependencies, e.g., web3.js -->
</head>
<body>
    <!-- HTML elements for dapp UI -->
    <h1>Welcome to My Dapp</h1>
    <button id="myButton">Click Me</button>

    <script src="app.js"></script>
</body>
</html>
// app.js
// Connect to the web3 provider and interact with your smart contract
// For example, using web3.js

// Your JavaScript code here

Step 4: Compile and Deploy the Smart Contract

To compile your Solidity smart contract and deploy it to the Spheron platform.

Step 5: Publish your project on spheron

The spheron publish command allows you to upload your project using the configuration that is described in the spheron.json file of your project.

spheron publish

Here is an example of how the result will look:

Spheron CLI 1.0.7

Publishing your dapp to IPFS ๐Ÿš€
Uploading directory build
Upload started, ID of deployment: 643fce207c3c7a0012df33a7
โ ™ Uploading to IPFS
โœ“ Success! Upload finished !
Here are upload details:
Upload ID: 643fce207c3c7a0012df33a7
Bucket ID: 643fce207c3c7a0012df33a5
Protocol Link: https://bafybeicrjwhn6nifl7tcuhkcitquvpumj426qa7r7ppcya5skmqly5n2la.ipfs.sphn.link
Dynamic Links: https://testapp-edab50.spheron.app
Template

Step 5: Interact with the Dapp

Once your dapp is deployed, you can interact with it using a web3-enabled browser or application. Retrieve the contract address from the deployment output, and use it to interact with the smart contract functions in your JavaScript code.

Step 6: Test and Enhance

Testing and enhancing your dapp is an iterative process. Utilize testing frameworks like Truffle or Hardhat to write comprehensive.

And That's it Hureyyyy YOU're ready with your first dapp created using Spheron CLI.

0
Subscribe to my newsletter

Read articles from Degen HODLer directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Degen HODLer
Degen HODLer

Passionate web3 enthusiast, dev looking to explore web3.