{"id":22416284,"url":"https://github.com/bunsdev/functions-workshop","last_synced_at":"2025-08-01T01:31:05.044Z","repository":{"id":235345203,"uuid":"790367092","full_name":"BunsDev/functions-workshop","owner":"BunsDev","description":"Using OpenAI to post a price forecast on-chain using Chainlink Functions","archived":false,"fork":false,"pushed_at":"2024-06-03T13:28:12.000Z","size":1438,"stargazers_count":13,"open_issues_count":0,"forks_count":19,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-03T15:17:50.456Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.youtube.com/watch?v=laASzWGxz2E","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BunsDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-04-22T18:47:40.000Z","updated_at":"2024-06-03T15:17:54.329Z","dependencies_parsed_at":"2024-05-02T23:49:45.011Z","dependency_job_id":null,"html_url":"https://github.com/BunsDev/functions-workshop","commit_stats":null,"previous_names":["bunsdev/functions-workshop"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BunsDev%2Ffunctions-workshop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BunsDev%2Ffunctions-workshop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BunsDev%2Ffunctions-workshop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BunsDev%2Ffunctions-workshop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BunsDev","download_url":"https://codeload.github.com/BunsDev/functions-workshop/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228321225,"owners_count":17901604,"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-12-05T15:15:36.987Z","updated_at":"2024-12-05T15:15:38.329Z","avatar_url":"https://github.com/BunsDev.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Block Magic Functions Workshop\nIn this workshop, we will build a price forecast to help inform the direction of a trade transaction.\n\n## Getting Started\n- [Install Foundry and Rust](/docs/INSTALL.md)\n- [Foundry Guide](/docs/FOUNDRY.md)\n- [OpenAI API Key](https://platform.openai.com/api-keys)\n\n## Overview of Functions\nChainlink functions enables you to leverage the power of a decentralized oracle network (DON) to execute external function calls (off-chain) to inform on-chain interactions.\n\nChainlink is able to execute a user-defined function via a DON, which comes to consensus on the results and reports the median result to the requesting contract via a callback function.\n\n---\n\n## Functions Workflow\n\n### 0. Install Dependencies\n```\nyarn\n```\n\n### 1. Setup Environment Variables\n\n#### Create Password\nChainlink Functions enables you to securely share secrets with the DON. Secrets are encrypted with a password.\n```\nyarn set:pw\n```\nOnce the ecrpytion key is created with your desired password, you can safely share your secrets with the DON, which requires multiple nodes to decrypt with consensus.\n\n#### Store Variables\n\nWe may now safely store environment variables without worrying about them being exposed, since they will be encrypted with your desired password. \n\nThese variables will be stored in a file called `.env.enc`.\n\n```\nyarn set:env\n```\nAfter running the command, you'll be prompted to enter the following for each variable to be encrypted:\n\n- **Name**: used to identify the variable.\n\n- **Value**: your (*unencrypted*) environment variable (*secret*).\n\nFor this demonstration, you will need to add the following to your encrypted environment variables:\n- `OPENAI_KEY`\n- `PRIVATE_KEY`\n- `ETHERSCAN_API_KEY`\n\n### 2. Simulate Functions\nBefore deploying, it's useful to simulate the execution of your function to ensure the output of your function execution is as expected.\n\nYou may simulate your function using the command below.\n\n```\nyarn simulate\n```\n\nFor full details on creating HTTP requestion via functions, read our [API Reference Documentation](https://docs.chain.link/chainlink-functions/api-reference/javascript-source).\n\n### 3. Deploy Consumer\n\n```\nyarn deploy\n```\n\n**Note**: ensure you have updated the deployment script to align with your target blockchain configurations.\n\n### 4. Create Subscription\nFund a new Functions billing subscription via the [Chainlink Functions UI](https://functions.chain.link/) and add your deployed Consumer Contract as a an authorized consumer to your subscription OR do so programmatically, as follows: \u003cbr /\u003e\n```\nnpx hardhat func-sub-create --network ethereumSepolia --amount \u003cLINK_AMOUNT\u003e --contract \u003cCONSUMER_ADDRESS\u003e\n```\n\n### 5. Make Requests\nFunctions enable you to make requests via the consumer contract. Before requesting, make sure you have successfully compiled your FunctionConsumer Contract, otherwise the request will fail to process.\n\nYou may do this programmatically with: \u003cbr/\u003e\n```\nnpx hardhat func-request --network \u003cNETWORK_NAME\u003e --contract \u003cCONSUMER_ADDRESS\u003e --subid \u003cSUBSCRIPTION_ID\u003e\n``` \n\nYou will see a confirmation request, so hit `Y` and press enter. \n\nOnce the request is fulfilled the console will show the response (decoded into the relevant return type) from the execution of your custom JS script.\n\n### 6. Make Queries\nYou are also able to query the response that was stored in your Functions Consumer contract either through the [Functions UI](https://functions.chain.link/) or programmatically as follows: \u003cbr/\u003e\n```\nnpx hardhat func-read --contract \u003cCONSUMER_ADDRESS\u003e --network \u003cNETWORK_NAME\u003e\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbunsdev%2Ffunctions-workshop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbunsdev%2Ffunctions-workshop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbunsdev%2Ffunctions-workshop/lists"}