Added README and compile command
6 files changed
tree: 33ad2f3f86d038e2b305ab128e021eb95f150318
  1. node_modules/
  2. scripts/
  3. config.js
  4. index.js
  5. LICENSE
  6. package-lock.json
  7. package.json
  8. README.md
  9. token.sol
README.md

ResDB Smart Contracts CLI πŸš€

The ResDB Smart Contracts CLI is a tool for creating, deploying, and managing smart contracts within the ResilientDB ecosystem. It is designed to work seamlessly with other ResilientDB projects, providing a streamlined interface for developers.

Features ✨

  • Create Smart Contracts: Generate new smart contract templates.
  • Deploy Smart Contracts: Deploy contracts to the blockchain.
  • Manage Contracts: Interact with and manage deployed contracts.

Exploring Leading Technologies πŸ”

Key Technologies

  • Truffle Framework: A development framework for Ethereum, offering tools for crafting, testing, and deploying smart contracts with Solidity.
  • Ganache: A personal Ethereum development blockchain, enabling contract deployment, application creation, and testing locally.
  • Metamask: A browser extension and Ethereum wallet for interacting with Ethereum Dapps directly from the browser.

Getting Started with ResDB Smart Contracts CLI πŸš€

Prerequisites

Before installing and using the Smart Contracts CLI, ensure you have the following prerequisites installed on your system:

Node.js and npm

Node.js and npm are required to run the Smart Contracts CLI. Follow the instructions below to install them based on your operating system.

Linux (Ubuntu/Debian)

sudo apt update
sudo apt install -y nodejs npm

MacOS

brew update
brew install node

Configuration Management with config.js βš™οΈ

The Role of ResDB_Home

The ResDB_Home path points to the directory where the ResilientDB installation resides. This path allows the CLI to locate and execute ResilientDB-related binaries and scripts.

config.js Implementation

The config.js file contains logic to prompt the user for the ResDB_Home path the first time they use the CLI and then stores this path for future use. Here’s how it works:

  1. Environment Variable Check: Checks if the ResDB_Home environment variable is already set.
  2. Configuration File Check: Checks a configuration file (~/.smart-contracts-cli-config.json) to see if the ResDB_Home path has been saved previously.
  3. User Prompt: Prompts the user to enter the ResDB_Home path if neither the environment variable nor the configuration file provides it.
  4. Saving the Path: Stores the provided path in both the environment variable and the configuration file.

config.js Code

const path = require('path');
const inquirer = require('inquirer');
const fs = require('fs-extra');
const os = require('os');

const CONFIG_FILE_PATH = path.join(os.homedir(), '.smart-contracts-cli-config.json');

async function getResDBHome() {
  if (process.env.ResDB_Home) {
    return process.env.ResDB_Home;
  }

  if (await fs.pathExists(CONFIG_FILE_PATH)) {
    const config = await fs.readJson(CONFIG_FILE_PATH);
    if (config.resDBHome) {
      process.env.ResDB_Home = config.resDBHome;
      return config.resDBHome;
    }
  }

  return null;
}

async function setResDBHome(resDBHome) {
  process.env.ResDB_Home = resDBHome;
  await fs.writeJson(CONFIG_FILE_PATH, { resDBHome });
}

async function promptForResDBHome() {
  const answers = await inquirer.prompt([
    {
      type: 'input',
      name: 'resDBHome',
      message: 'Please enter the ResDB_Home path:',
    },
  ]);

  const resDBHome = answers.resDBHome;
  await setResDBHome(resDBHome);

  return resDBHome;
}

module.exports = {
  getResDBHome,
  setResDBHome,
  promptForResDBHome,
};

Usage

To get started with the ResDB Smart Contracts CLI:

  1. Clone the repository.
  2. Install the dependencies with npm install.
  3. Run the CLI with smart-contracts-cli <command> <options>.
  4. Follow the prompts to set up your ResDB_Home path.

Commands

Create Command

The create command initializes a new account using ResilientDB's smart contract tools.

Usage

smart-contracts-cli create --config <path_to_config>
  • path_to_config: Path to the configuration file.

Compile Command

The compile command compiles a Solidity smart contract into a JSON file using solc.

smart-contracts-cli compile <inputFile.sol> <outputFile.json>
  • inputFile.sol: Path to the Solidity smart contract file.
  • outputFile.json: Name of the resulting JSON file.

Make sure solc (Solidity compiler) is installed on your system. Refer to the Prerequisites section in the README for installation instructions.