The ResContract CLI is a command-line tool for creating, deploying, and managing smart contracts within the ResilientDB ecosystem. It provides a streamlined interface for developers and students to interact with smart contracts efficiently.
- Create Smart Contracts: Generate new smart contract templates.
- Compile Contracts: Compile Solidity contracts to JSON.
- Deploy Smart Contracts: Deploy contracts to the blockchain with automatic registry tracking.
- Address Management: Add external addresses to the system.
- Deployment Registry: Track and manage deployed contracts with built-in registry commands.
Before installing and using the ResContract CLI, ensure you have the following prerequisites installed on your system:
- Node.js (version >= 14): Download and install Node.js
- npm: Comes with Node.js. Ensure it's up-to-date.
- Solidity Compiler (
solc): Required to compile smart contracts.
sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install -y solcbrew update
brew upgrade
brew tap ethereum/ethereum
brew install solidityInstall the ResContract CLI globally using npm:
npm install -g rescontract-cliBefore using the ResContract CLI, you must set the ResDB_Home environment variable or provide the path to your ResilientDB installation in a config.yaml file. The CLI will not prompt you for this path and will exit with an error if it's not set.
Set the ResDB_Home environment variable to point to the directory where ResilientDB is installed.
Linux/macOS:
export ResDB_Home=/path/to/resilientdbAdd the above line to your .bashrc or .zshrc file to make it persistent.
Update the config.yaml file in the same directory where you run the rescontract command or in your home directory.
Example config.yaml:
ResDB_Home: /path/to/resilientdbEnsure the ResDB_Home path is correct.
Note: The CLI checks for
config.yamlin the current directory first, then in your home directory.
After installation, you can use the rescontract command in your terminal.
rescontract <command> [options]Initializes a new account using ResilientDB's smart contract tools.
Usage:
rescontract create --config <path_to_config>--config, -c: Path to the configuration file.
Example:
rescontract create --config ~/resilientdb/config/service.configCompiles a Solidity smart contract into a JSON file using solc.
Usage:
rescontract compile --sol <inputFile.sol> --output <outputFile.json>--sol, -s: Path to the Solidity smart contract file.--output, -o: Name of the resulting JSON file.
Example:
rescontract compile --sol contracts/MyToken.sol --output build/MyToken.jsonDeploys the smart contract to the blockchain.
Usage:
rescontract deploy --config <service.config> --contract <contract.json> \
--name <tokenName> --arguments "<parameters>" --owner <address>--config, -c: Client configuration path.--contract, -p: Path to the contract JSON file.--name, -n: Name of the contract.--arguments, -a: Parameters to create the contract object (enclosed in quotes).--owner, -m: Contract owner's address.
Example:
rescontract deploy --config ~/resilientdb/config/service.config \
--contract build/MyToken.json --name MyToken \
--arguments "1000000" --owner 0xYourAddressAdds an external address to the system for contract interactions.
Usage:
rescontract add_address --config <path> --external-address <address>--config, -c: Path to the configuration file.--external-address, -e: External address to add to the system.
Example:
rescontract add_address --config ~/resilientdb/config/service.config \
--external-address 0xExternalAddressLists all deployed contracts tracked in the registry.
Usage:
rescontract list-deploymentsExample:
rescontract list-deploymentsThis command displays all deployed contracts with their owner addresses, contract names, and contract addresses.
Clears the deployed contracts registry.
Usage:
rescontract clear-registryExample:
rescontract clear-registryWarning: This command permanently removes all deployment tracking information.
The ResContract CLI automatically tracks all deployed contracts in a registry file located at ~/.rescontract_deployed_contracts.json. This registry provides several benefits:
- Duplicate Prevention: Prevents deploying the same contract with the same owner and name
- Contract Tracking: Maintains a record of all deployed contracts with their addresses
- Easy Management: Use
list-deploymentsto view all contracts andclear-registryto reset
The registry stores the following information for each deployment:
- Owner address
- Contract name
- Contract address
- Deployment timestamp
This project is licensed under the MIT License - see the LICENSE file for details.