npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

smart-contracts-cli

v1.0.1

Published

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.

Downloads

62

Readme

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:

solc

solc is required to compile the smart contracts. Install solc on Linux using the following commands:

sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install -y solc

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.
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 sudo npm install -g.
  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.

Usage

smart-contracts-cli compile -s <inputFile.sol> -o <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.

Deploy Command

The deploy command deploys the smart contract.

Usage

smart-contracts-cli deploy --config <service.config> --contract <contract.json> \
--name <tokenName> --arguments <parameters> --owner <address> 
  • service.config: Client configuration path
  • contract.json: Path to the contract json file
  • tokenName: Name of the contract created
  • parameters: Parameters to create the contract object
  • address: Contract owner's address

Execute Command

The execute command executes a smart contract function using ResilientDB's smart contract tools.

Usage

smart-contracts-cli execute --config <service.config> --sender <senderAddress> \
--contract <contractAddress> --function <functionName> --arguments <parameters>
  • service.config: Path to the client configuration file.
  • senderAddress: Address of the sender executing the function.
  • contractAddress: Address of the deployed contract.
  • functionName: Name of the function to execute.
  • parameters: Arguments to pass to the function.

Example:

smart-contracts-cli execute --config service/tools/config/interface/service.config \
--sender 0x67c6697351ff4aec29cdbaabf2fbe3467cc254f8 \
--contract 0xfc08e5bfebdcf7bb4cf5aafc29be03c1d53898f1 \
--function "transfer(address,uint256)" \
--arguments "0x1be8e78d765a2e63339fc99a66320db73158a35a,100"