{"id":15286052,"url":"https://github.com/dkackman/chia-repl","last_synced_at":"2025-04-13T03:08:06.405Z","repository":{"id":38187269,"uuid":"478364190","full_name":"dkackman/chia-repl","owner":"dkackman","description":"A REPL tool for Chia","archived":false,"fork":false,"pushed_at":"2023-09-10T15:45:21.000Z","size":3957,"stargazers_count":22,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-13T03:08:00.094Z","etag":null,"topics":["blockchain","chia","chia-blockchain","clvm","crypto","nft","nodejs","repl"],"latest_commit_sha":null,"homepage":"","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/dkackman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2022-04-06T01:48:41.000Z","updated_at":"2023-08-28T14:09:56.000Z","dependencies_parsed_at":"2024-06-19T19:04:54.649Z","dependency_job_id":"05a80794-2618-4603-a547-cd1d6af168fa","html_url":"https://github.com/dkackman/chia-repl","commit_stats":{"total_commits":349,"total_committers":3,"mean_commits":"116.33333333333333","dds":0.03724928366762181,"last_synced_commit":"9cd01336f0b0439d67fc0863009052cc9607d2ad"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dkackman%2Fchia-repl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dkackman%2Fchia-repl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dkackman%2Fchia-repl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dkackman%2Fchia-repl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dkackman","download_url":"https://codeload.github.com/dkackman/chia-repl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248657918,"owners_count":21140846,"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":["blockchain","chia","chia-blockchain","clvm","crypto","nft","nodejs","repl"],"created_at":"2024-09-30T15:10:17.330Z","updated_at":"2025-04-13T03:08:06.376Z","avatar_url":"https://github.com/dkackman.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chia-repl\n\n[![CodeQL](https://github.com/dkackman/chia-repl/actions/workflows/codeql.yml/badge.svg)](https://github.com/dkackman/chia-repl/actions/workflows/codeql.yml)\n[![Node.js CI](https://github.com/dkackman/chia-repl/actions/workflows/node.js.yml/badge.svg)](https://github.com/dkackman/chia-repl/actions/workflows/node.js.yml)\n  \u003ca href=\"https://www.npmjs.com/package/chia-repl\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/chia-repl.svg?sanitize=true\" alt=\"Version\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/chia-repl\"\u003e\u003cimg src=\"https://img.shields.io/npm/l/chia-repl.svg?sanitize=true\" alt=\"Version\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/chia-repl\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/chia-repl.svg?sanitize=true\" alt=\"Monthly Downloads\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/chia-repl\"\u003e\u003cimg src=\"https://img.shields.io/npm/dt/chia-repl.svg?sanitize=true\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n\nA REPL tool for Chia that incorporates various chia and crypto utilities in a single, interactive node environment.\n\n- [Chia RPC](https://dkackman.github.io/chia-api/)\n- [clvm_tools-js](https://github.com/Chia-Mine/clvm_tools-js)\n- [clvm-js](https://github.com/Chia-Mine/clvm-js)\n- [chia-utils](https://github.com/CMEONE/chia-utils)\n- [@rigidity/bls-signatures](https://github.com/Rigidity/bls-signatures)\n- [chia-daemon](https://github.com/dkackman/chia-repl/tree/main/packages/chia-daemon)\n- [chia-nft-minter](https://github.com/dkackman/chia-repl/tree/main/packages/chia-nft-minter)\n\nThe wiki has [more examples and detail](https://github.com/dkackman/chia-repl/wiki).\n\n## Packaged\n\n```shell\nnpm install -g chia-repl\nchia-repl\n🌿 Welcome to Chia!\n🌿 \n```\n\n## From Source\n\n```shell\nnpm install\nnpm start -w chia-repl\n\u003e chia-repl@0.12.3 start\n\u003e node index.js\n\n🌿 Welcome to Chia!\n🌿 \n```\n\nUses the [node repl](https://nodejs.org/api/repl.html) so the CLI works like node's.\n\n## Commands\n\nREPL commands always start with `.` and are lsited with `.help`.\n\n```bash\n🌿 .help\n.break              Sometimes you get stuck, this gets you out\n.clear              Break, and also clear the local context\n.connect            Opens the websocket connection to the chia daemon using the currently loaded connection\n.credits            Shows credits for the various tool authors\n.disconnect         Closes the websocket connection to the chia daemon\n.editor             Enter editor mode\n.exit               Exit the REPL\n.help               Print this help message\n.list-connections   Displays a list of saved connection names\n.listen             Opens the websocket connection to the chia daemon and listens for `wallet_ui` messages\n.load               Load JS from a file into the REPL session\n.load-connection    Loads a saved connection with an optional name\n.more-help          Shows more help about using the environment\n.save               Save all evaluated commands in this REPL session to a file\n.save-connection    Saves the current connection with an optional name\n.save-options       Saves the options\n.version            Shows the version of this application\n\nPress Ctrl+C to abort current expression, Ctrl+D to exit the REPL\n🌿\n```\n\n## Globals\n\nVarious global objects and functions are available within the REPL environment and can be listed with `.more-help`.\nSome of these configure the connection and REPL options, while other enable interaction with the chia node, utility functions, and the clvm.\n\n```bash\n🌿 .more-help\nThese global objects are available within the REPL environment\nbls             BLS signature functions\nchia            Chia node rpc services. This object is only availble after a successful .connect\n                All functions on these chia services are async \u0026 awaitable: crawler, daemon, farmer, full_node, harvester, wallet, simulator\nclvm_tools      clvm_tools-js functions (run, brun, opc, opd, read_ir)\nclvm            clvm-js (Program, SExp etc.)\nutils           Chia-utils (bech32m and other helpers)\nconnection      Properties of the current connection\noptions         Configurable REPL options\ncontentHasher   A helper to generate NFT compatible hashes for files or remote resources\nmetadataFactory A helper to generate NFT and Collection metadata\nminter          The NFT minter. Only availble when connected to the chia daemon\nrepl.builtinModules\n                Show other available builtin node modules\n\nThese global functions are invocable within the REPL environment\ncompile(chiaLisp, prefix, ...compileArgs)\n                Compiles a chialisp program into its address, clvm, puzzle, and puzzle_hash\ntest(chiaLisp, compileArgs = [], programArgs = []))\n                Runs a chialisp program and displays its output\n```\n\n## Examples\n\nThe global `connection` context object has the host, port, and path to cert files. These properties can be set inside the repl with `connection.host = \"my-host\"` etc.\nOnce connected to the `daemon` each of the service endpoints becomes availalbe as an awaitable context function.\n\nKnowing [the chia rpc api](https://dkackman.github.io/chia-api/) will help immensely. All endpoints and data payloads should work. Since it is a full nodejs REPL environment, core modules like `fs` and `http` are available.\n\n### Mint a simple NFT\n\n```javascript\n🌿 let dataFileInfo = {\n    name: 'test-nft-by-you',\n    type: 'image/jpg',\n    filepath: 'E:\\\\nft\\\\flower.jpg'\n};\n🌿 let mintingInfo = {\n    wallet_id: 2,\n    target_address: 'txch10kn82kl6hqv47qzeh4ugmqjr5mmdcnrlymfx8wl9nrhhkyxnzfkspna7l9',\n};\n🌿 let collectionMetaData = metadataFactory.createCollectionMetadata('test-nft-collection-by-you');\n🌿 let nftMetadata = metadataFactory.createNftMetadata('test-nft-by-you', collectionMetaData);\n🌿 await minter.createNftFromFile(dataFileInfo, mintingInfo, nftMetadata);\n{\n  spend_bundle: {\n    aggregated_signature: '0x99e39df189f009a4679067d212a6845b7bfec05452d9696de79907a861239de3cbd247a27c39b2ca2492740f9f4aab58028ebf035f40597d16ddeee5194f8dfaa8c8ec8e90b6c91fce60944f0e55997b443be63ed8e9dcb9d685a9b473e1b441',\n    coin_solutions: [ [Object], [Object], [Object] ]\n  },\n  success: true,\n  wallet_id: 2\n}\n```\n\n### Run a CLVM Program\n\n```javascript\n🌿 const {SExp, OPERATOR_LOOKUP, KEYWORD_TO_ATOM, h, t, run_program} = clvm;\n🌿 const plus = h(KEYWORD_TO_ATOM[\"+\"]);\n🌿 const q = h(KEYWORD_TO_ATOM[\"q\"]);\n🌿 const program = SExp.to([plus, 1, t(q, 175)]);\n🌿 const env = SExp.to(25);\n🌿 const [cost, result] = run_program(program, env, OPERATOR_LOOKUP);\n🌿 let isEqual = result.equal_to(SExp.to(25 + 175));\n🌿 isEqual = result.as_int() === (25 + 175);\ntrue\n🌿 cost\n833\n🌿 result\nSExp { _atom: Bytes { _b: Uint8Array(2) [ 0, 200 ] }, _pair: null }\n🌿 \n```\n\n### Compile a Simple Program with clvm_tools\n\n```lisp\n🌿 clvm_tools.run(\"(mod ARGUMENT (+ ARGUMENT 3))\")\n'(+ 1 (q . 3))'\n🌿 clvm_tools.brun(_, '1')\n'4'\n🌿\n```\n\n### Compile a Simple Program From a File\n\n```lisp\n🌿 clvm_tools.run('../examples/factorial.clsp')\n'(a (q 2 2 (c 2 (c 5 ()))) (c (q 2 (i (= 5 (q . 1)) (q 1 . 1) (q 18 5 (a 2 (c 2 (c (- 5 (q . 1)) ()))))) 1) 1))'\n🌿 clvm_tools.brun(_, '(5)')\n'120'\n🌿\n```\n\n### Compile a ChiaLisp Program\n\n```lisp\n🌿 compile('../examples/piggybank.clsp', 'xch', '-i../examples/include')\n{\n  address: 'tcxh1smq2mvt8mdmulp7q5tvwh8rn8g6u8ykfr5020a3aj3mj3hsha5ns3zea78',\n  clvm: '(a (q 2 (i (\u003e 11 5) (q 2 (i (\u003e 11 14) (q 4 (c 10 (c 4 (c 11 ()))) (c (c 10 (c 23 (q ()))) ())) (q 4 (c 10 (c 23 (c 11 ()))) ())) 1) (q 8)) 1) (c (q 0xcafef00d 51 . 500) 1))', \n  puzzle: 'ff02ffff01ff02ffff03ffff15ff0bff0580ffff01ff02ffff03ffff15ff0bff0e80ffff01ff04ffff04ff0affff04ff04ffff04ff0bff80808080ffff04ffff04ff0affff04ff17ffff01ff80808080ff808080ffff01ff04ffff04ff0affff04ff17ffff04ff0bff80808080ff808080ff0180ffff01ff088080ff0180ffff04ffff01ff84cafef00dff338201f4ff018080',\n  puzzle_hash: '86c0adb167db77cf87c0a2d8eb9c733a35c392c91d1ea7f63d947728de17ed27'\n}\n```\n\n### Test a ChiaLisp Program\n\n```lisp\n🌿 test('(mod ARGUMENT (+ ARGUMENT 3))', [], [ '15' ])\n'18'\n```\n\n### Connecting and Calling a Node Function\n\n```javascript\n🌿 .connect\nConnecting to wss://localhost:55400...\ndone\n🌿 await chia.full_node.get_network_info()\n{ network_name: 'testnet10', network_prefix: 'txch', success: true }\n🌿\n```\n\n### Chaining Calls\n\nSince it is a javascript environment, variables can be defined and set, and are preserved through. The [special value](https://nodejs.org/api/repl.html#assignment-of-the-_-underscore-variable) `_` can also be used to chain function calls.\n\n```javascript\n🌿 await chia.full_node.get_blockchain_state()\nblockchain_state: {\n  ...\n}\n🌿 _.blockchain_state.peak.header_hash\n'0x098b7fd5768174776eb4a29cedcabffb21c487b592c73f72ac33bc4ffecf6c38'\n🌿 await chia.full_node.get_block({ header_hash: _ })\n{\n  block: {\n    ...\n  }\n}\n🌿\n```\n\n### OpenAPI Helpers for RPC Payloads\n\n```javascript\n🌿 chia.daemon.getPayloadDescriptor('is_running')\n{\n  type: 'object',\n  required: [ 'service' ],\n  properties: { service: { type: 'string' } }\n}\n🌿 var p = chia.daemon.makePayload('is_running')\nundefined\n🌿 p.service = 'chia_fulll_node'\n'chia_fulll_node'\n🌿 await chia.daemon.is_running(p)\n{ is_running: false, service_name: 'chia_fulll_node', success: true }\n```\n\n### BLS Support\n\n```javascript\n🌿 var seed = Uint8Array.from([\n...   0,  50, 6,  244, 24,  199, 1,  25,  52,  88,  192,\n...   19, 18, 12, 89,  6,   220, 18, 102, 58,  209, 82,\n...   12, 62, 89, 110, 182, 9,   44, 20,  254, 22\n... ]);\nundefined\n🌿 bls.AugSchemeMPL.keyGen(seed)\n$38c91b9e16a98741$export$8f54525b330fd87b {\n  value: 25076100791286022435148702897030204761993316905161740767284798605189048279853n\n}\n🌿\n```\n\n___\n\n_chia and its logo are the registered trademark or trademark of Chia Network, Inc. in the United States and worldwide._\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdkackman%2Fchia-repl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdkackman%2Fchia-repl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdkackman%2Fchia-repl/lists"}