| commit | 524d7efab318af53584250248912e0287de48d2c | [log] [tgz] |
|---|---|---|
| author | gopuman <gopuman@node0.gopuman-217480.resilientdb-pg0.utah.cloudlab.us> | Fri Sep 13 20:16:38 2024 -0600 |
| committer | gopuman <gopuman@node0.gopuman-217480.resilientdb-pg0.utah.cloudlab.us> | Fri Sep 13 20:16:38 2024 -0600 |
| tree | 83ed84ea273910453fb084cea4cfd3a52f9621fb | |
| parent | 49ad88df3186ea3d32097f7a7bf2e678b7a3cb4e [diff] |
Added README
This repository provides a GraphQL API that allows users to make API calls to a running smart-contracts-cli backend. The API supports various functions to interact with smart contracts, including creating accounts, compiling contracts, deploying contracts, and executing contract functions.
Before you begin, ensure you have the following prerequisites:
ResilientDB: A running instance of ResilientDB with the smart contracts service running. You can find more information and setup instructions here: ResilientDB
Smart Contracts CLI: A running instance of the smart-contracts-cli. You can find more information and setup instructions here: smart-contracts-cli.
To set up the project, follow these steps:
Clone the repository:
git clone https://github.com/yourusername/smart-contracts-graphql.git cd smart-contracts-graphql
Install dependencies:
npm install
Start the server:
node server.js
The server will start running on port 4000. You can access the GraphQL API at http://localhost:4000/graphql.
The GraphQL API supports the following queries:
createAccountCreates a new account using the specified configuration file.
Arguments:
config (String): Path to the configuration file.compileContractCompiles a smart contract from the specified source path and outputs the compiled contract to the specified output path.
Arguments:
sourcePath (String): Path to the source file of the smart contract.outputPath (String): Path to the output file for the compiled contract.deployContractDeploys a smart contract using the specified configuration, contract file, contract name, arguments, and owner address.
Arguments:
config (String): Path to the configuration file.contract (String): Path to the contract file.name (String): Name of the contract.arguments (String): Arguments for the contract constructor.owner (String): Owner address.executeContractExecutes a function of a deployed smart contract.
Arguments:
config (String): Path to the configuration file.sender (String): Address of the sender.contract (String): Name of the contract.function (String): Name of the function to execute.arguments (String): Arguments for the function.Here are some sample queries you can run:
Create Account:
{ createAccount(config: "incubator-resilientdb/service/tools/config/interface/service.config") }
Explanation: This query creates a new account using the specified configuration file. The config argument points to the path of the configuration file that contains necessary settings for creating the account. The function returns a string indicating the success or failure of the account creation process.
Compile Contract:
{ compileContract(sourcePath: "contracts/MyContract.sol", outputPath: "build/MyContract.json") }
Explanation: This query compiles a smart contract from the specified source file and outputs the compiled contract to the specified output file. The sourcePath argument is the path to the source file of the smart contract (in this case, contracts/MyContract.sol), and the outputPath argument is the path where the compiled contract will be saved (in this case, build/MyContract.json). The function returns a string indicating the success or failure of the compilation process.
Deploy Contract:
{ deployContract( config: "incubator-resilientdb/service/tools/config/interface/service.config", contract: "build/MyContract.json", name: "MyContract", arguments: "1000", owner: "0x1be8e78d765a2e63339fc99a66320db73158a35a" ) }
Explanation: This query deploys a smart contract using the specified configuration, contract file, contract name, arguments, and owner address. The function returns a string indicating the success or failure of the deployment process.
Execute Contract:
{ executeContract( config: "incubator-resilientdb/service/tools/config/interface/service.config", sender: "0x1be8e78d765a2e63339fc99a66320db73158a35a", contract: "MyContract", function: "transfer", arguments: "0xRecipientAddress,100" ) }
Explanation: This query executes a function of a deployed smart contract. The arguments are as follows:
config: Path to the configuration file.sender: Address of the sender who is executing the contract function.contract: Name of the contract.function: Name of the function to execute (in this case, transfer).arguments: Arguments for the function (in this case, transferring 100 tokens to 0xRecipientAddress).