{"id":21156938,"url":"https://github.com/resilientecosystem/smart-contracts-graphql","last_synced_at":"2025-03-14T15:23:53.553Z","repository":{"id":256650730,"uuid":"853128270","full_name":"ResilientEcosystem/smart-contracts-graphql","owner":"ResilientEcosystem","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-18T00:23:09.000Z","size":81,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-19T14:01:57.897Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ResilientEcosystem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-06T03:38:39.000Z","updated_at":"2024-10-18T00:23:09.000Z","dependencies_parsed_at":"2024-09-12T07:58:23.676Z","dependency_job_id":"275a835b-eb79-4e55-887b-be6a69cab651","html_url":"https://github.com/ResilientEcosystem/smart-contracts-graphql","commit_stats":null,"previous_names":["resilientecosystem/smart-contracts-graphql"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ResilientEcosystem%2Fsmart-contracts-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ResilientEcosystem%2Fsmart-contracts-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ResilientEcosystem%2Fsmart-contracts-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ResilientEcosystem%2Fsmart-contracts-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ResilientEcosystem","download_url":"https://codeload.github.com/ResilientEcosystem/smart-contracts-graphql/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243598659,"owners_count":20316997,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-20T11:55:32.216Z","updated_at":"2025-03-14T15:23:53.520Z","avatar_url":"https://github.com/ResilientEcosystem.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Smart Contracts GraphQL API \n\nThis repository provides a GraphQL API that allows users to interact with smart contracts in the ResilientDB ecosystem through a set of GraphQL queries and mutations. The API leverages the `rescontract-cli` tool to perform various functions, including creating accounts, compiling contracts, deploying contracts, and executing contract functions.\n\n## Table of Contents\n\n- [Prerequisites](#prerequisites)\n- [Installation](#installation)\n- [Configuration](#configuration)\n- [Running the Server](#running-the-server)\n- [GraphQL API](#graphql-api)\n  - [Mutations](#mutations)\n- [Sample Mutations](#sample-mutations)\n\t- [Using Type “path”](#using-type-path)\n\t- [Using Type “data”](#using-type-data)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Prerequisites\n\nBefore you begin, ensure you have the following prerequisites:\n\n1. **ResilientDB**: A running instance of ResilientDB with the smart contracts service running. More information and setup instructions can be found here: [ResilientDB](https://github.com/apache/incubator-resilientdb)\n\n2. **ResContract CLI**: Install the `rescontract-cli` tool globally. Follow the instructions in the [ResContract CLI Repository](https://github.com/ResilientEcosystem/ResContract) to install and configure it.\n\n   ```bash\n   npm install -g rescontract-cli\n   ```\n\n3.  **Node.js (version \u003e= 15.6.0)**:  Download and install Node.js version 15.6.0 or higher, as the application uses crypto.randomUUID() which was introduced in Node.js v15.6.0.\n\n\t```bash\n\t# You can check your Node.js version with:\n\tnode -v\n\t```\n\n\n**The prerequisites listed above can be installed using the `INSTALL.sh` script:**\n\n   ```bash\n   chmod +x INSTALL.sh\n   ./INSTALL.sh\n   ```\n\n## Installation\n\nTo set up the project, follow these steps:\n\n1.  **Clone the repository**:\n    \n\t```bash\n    git clone https://github.com/ResilientEcosystem/smart-contracts-graphql.git\n    cd smart-contracts-graphql\n    ```\n    \n2.  **Install dependencies**:\n    \n    ```bash\n\t npm install\n\t```\n\n## Configuration\n\nEnsure that the  `ResContract CLI`  is properly configured. You need to set the  `ResDB_Home`  environment variable or provide a  `config.yaml`  file as required by the CLI.\n\nRefer to the  [ResContract CLI README](https://github.com/ResilientEcosystem/ResContract#configuration-)  for detailed instructions.\n\n## Running the Server\n\nStart the server using the following command:\n\n```bash\nnpm start\n```\n\nThe server will start running on port  `8400`. You can access the GraphQL API at  `http://localhost:8400/graphql`.\n\n## GraphQL API\n\nThe GraphQL API supports the following mutations to interact with smart contracts.\n\n### Mutations\n\n#### `createAccount`\n\nCreates a new account using the specified configuration file.\n\n**Type**: Mutation\n\n**Arguments**:\n\n-   `config`  (String!): Configuration data or path to the configuration file.\n-   `type`  (String): Optional. Specifies whether config is data or a file path. Accepts \"data\" or \"path\". Defaults to \"path\".\n\n**Returns**: String - Address of the newly created account or an error message.\n\n#### `compileContract`\n\nCompiles a smart contract from the specified source.\n\n**Type**: Mutation\n\n**Arguments**:\n\n-   `source`  (String!): Solidity code or path to the source file of the smart contract.\n-   `type`  (String): Optional. Specifies whether config is data or a file path. Accepts \"data\" or \"path\". Defaults to \"path\".\n\n**Returns**: String - Name of the compiled contract JSON file or an error message.\n\n#### `deployContract`\n\nDeploys a smart contract using the specified configuration, contract file, contract name, arguments, and owner address.\n\n**Type**: Mutation\n\n**Arguments**:\n\n-   `config`  (String!): Configuration data or path to the configuration file.\n-   `contract`  (String!): Path to the contract JSON file.\n-   `name`  (String!): Name of the contract (include the full path and contract name).\n-   `arguments`  (String!): Constructor arguments for the contract (comma-separated).\n-   `owner`  (String!): Owner address.\n-   `type`  (String): Optional. Specifies whether config is data or a file path. Accepts \"data\" or \"path\". Defaults to \"path\".\n\n**Returns**: String - Details of the deployed contract or an error message.\n\n#### `executeContract`\n\nExecutes a function of a deployed smart contract.\n\n**Type**: Mutation\n\n**Arguments**:\n\n-   `config`  (String!): Configuration data or path to the configuration file.\n-   `sender`  (String!): Address of the sender.\n-   `contract`  (String!): Address of the deployed contract.\n-   `functionName`  (String!): Name of the function to execute (include parameter types).\n-   `arguments`  (String!): Arguments for the function (comma-separated).\n-   `type`  (String): Optional. Specifies whether config is data or a file path. Accepts \"data\" or \"path\". Defaults to \"path\".\n\n**Returns**: String - Result of the function execution or an error message.\n\n## Sample Mutations\n\nBelow are sample mutations demonstrating how to use the API with both \"path\" and \"data\" types.\n\n### Using type `path` \n\nThe `type` option defaults to \"path\" and doesn't have to be explicitly set. \n\n1. **Create Account**\n\n```graphql\nmutation {\n  createAccount(config: \"../incubator-resilientdb/service/tools/config/interface/service.config\")\n}\n```\n\n**Sample Response:**\n```json\n{\n  \"data\": {\n    \"createAccount\": \"0x67c6697351ff4aec29cdbaabf2fbe3467cc254f8\"\n  }\n}\n```\n\n**Explanation**: Creates a new account using the configuration file located at the specified path.\n\n2.  **Compile Contract**\n```graphql\nmutation {\n  compileContract(\n    source: \"token.sol\"\n  )\n}\n```\n\n**Sample Response:**\n```json\n{\n  \"data\": {\n    \"compileContract\": \"Compiled successfully to /users/yourusername/smart-contracts-graphql/compiled_contracts/MyContract.json\"\n  }\n}\n```\n**Explanation**: Compiles the smart contract located at token.sol and saves the compiled JSON to the compiled_contracts directory.\n\n3.  **Deploy Contract**\n```graphql\nmutation {\n  deployContract(\n    config: \"../incubator-resilientdb/service/tools/config/interface/service.config\",\n    contract: \"compiled_contracts/MyContract.json\",\n    name: \"token.sol:Token\",\n    arguments: \"1000\",\n    owner: \"0x67c6697351ff4aec29cdbaabf2fbe3467cc254f8\"\n  )\n  {\n    ownerAddress\n    contractAddress\n    contractName\n  }\n}\n```\n\n**Sample Response:**\n```json\n{\n  \"data\": {\n    \"deployContract\": {\n      \"ownerAddress\": \"0x67c6697351ff4aec29cdbaabf2fbe3467cc254f8\",\n      \"contractAddress\": \"0xfc08e5bfebdcf7bb4cf5aafc29be03c1d53898f1\",\n      \"contractName\": \"token.sol:Token\"\n    }\n  }\n}\n```\n**Explanation**: Deploys the compiled contract using the specified parameters.\n\n4.  **Execute Contract**\n```graphql\nmutation {\n  executeContract(\n    config: \"../incubator-resilientdb/service/tools/config/interface/service.config\",\n    sender: \"0x67c6697351ff4aec29cdbaabf2fbe3467cc254f8\",\n    contract: \"0xfc08e5bfebdcf7bb4cf5aafc29be03c1d53898f1\",\n    functionName: \"transfer(address,uint256)\",\n    arguments: \"0x1be8e78d765a2e63339fc99a66320db73158a35a,100\"\n  )\n}\n```\n\n**Sample Response:**\n```json\n{\n  \"data\": {\n    \"executeContract\": \"Execution successful\"\n  }\n}\n```\n**Explanation**: Executes the transfer function of the deployed contract, transferring 100 tokens to the specified address.\n\n\n### Using type `data` \n\nIn this mode, the API accepts configuration data and Solidity code directly, without needing file paths.\n\n1. **Create Account**\n\n```graphql\nmutation {\n  createAccount(\n    config: \"5 127.0.0.1 10005\",\n    type: \"data\"\n  )\n}\n```\n\n**Sample Response:**\n```json\n{\n  \"data\": {\n    \"createAccount\": \"0x255d051758e95ed4abb2cdc69bb454110e827441\"\n  }\n}\n```\n\n**Explanation**: Creates a new account using the provided configuration data.\n\n2.  **Compile Contract**\n```graphql\nmutation {\n  compileContract(\n    source: \"\"\"\n    pragma solidity ^0.8.0;\n\t\t...\n\t\t...\n    }\n    \"\"\",\n    type: \"data\"\n  )\n}\n```\n\n**Sample Response:**\n```json\n{\n  \"data\": {\n    \"compileContract\": \"contract-20f42b42-f56f-45e8-8264-33cf8d93f8be.json\"\n  }\n}\n```\n**Explanation**: Compiles the provided Solidity code and returns the name of the compiled contract JSON file stored in the compiled_contracts directory.\n\n3.  **Deploy Contract**\n```graphql\nmutation {\n  deployContract(\n    config: \"5 127.0.0.1 10005\",\n    contract: \"contract-20f42b42-f56f-45e8-8264-33cf8d93f8be.json\",\n    name: \"/path/to/.json/file:Token\",\n    arguments: \"1000\",\n    owner: \"0x255d051758e95ed4abb2cdc69bb454110e827441\",\n    type: \"data\"\n  )\n}\n```\n\n**Sample Response:**\n```json\n{\n  \"data\": {\n    \"deployContract\": \"owner_address: 0x255d051758e95ed4abb2cdc69bb454110e827441\\ncontract_address: 0xb616e4c564b03fe336333758739a7d7ee0227d5d\\ncontract_name: Token\"\n  }\n}\n```\n**Explanation**: Deploys the compiled contract using the configuration data and the compiled contract JSON file name returned from the compileContract mutation.\n\n4.  **Execute Contract**\n```graphql\nmutation {\n  executeContract(\n    config: \"5 127.0.0.1 10005\",\n    sender: \"0x255d051758e95ed4abb2cdc69bb454110e827441\",\n    contract: \"0xb616e4c564b03fe336333758739a7d7ee0227d5d\",\n    functionName: \"transfer(address,uint256)\",\n    arguments: \"0x213ddc8770e93ea141e1fc673e017e97eadc6b96,100\",\n    type: \"data\"\n  )\n}\n```\n\n**Sample Response:**\n```json\n{\n  \"data\": {\n    \"executeContract\": \"result: 0x0000000000000000000000000000000000000000000000000000000000000001\"\n  }\n}\n```\n**Explanation**: Executes the transfer function of the deployed contract, transferring 100 tokens to the specified address, using configuration data.\n\n## License\n\nThis project is licensed under the Apache License - see the  [LICENSE](LICENSE)  file for details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fresilientecosystem%2Fsmart-contracts-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fresilientecosystem%2Fsmart-contracts-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fresilientecosystem%2Fsmart-contracts-graphql/lists"}