{"id":21815748,"url":"https://github.com/bitcoin-com/oracles.cash","last_synced_at":"2025-04-14T00:53:44.710Z","repository":{"id":37903801,"uuid":"210056779","full_name":"Bitcoin-com/oracles.cash","owner":"Bitcoin-com","description":"Platform for creating oracles on Bitcoin Cash","archived":false,"fork":false,"pushed_at":"2023-11-28T05:49:02.000Z","size":2421,"stargazers_count":10,"open_issues_count":21,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-27T14:55:26.026Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bitcoin-com.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":"2019-09-21T21:40:46.000Z","updated_at":"2024-01-28T20:18:11.000Z","dependencies_parsed_at":"2024-11-27T19:15:15.428Z","dependency_job_id":null,"html_url":"https://github.com/Bitcoin-com/oracles.cash","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bitcoin-com%2Foracles.cash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bitcoin-com%2Foracles.cash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bitcoin-com%2Foracles.cash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bitcoin-com%2Foracles.cash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bitcoin-com","download_url":"https://codeload.github.com/Bitcoin-com/oracles.cash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248804784,"owners_count":21164131,"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-27T15:22:32.714Z","updated_at":"2025-04-14T00:53:44.683Z","avatar_url":"https://github.com/Bitcoin-com.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# oracles.cash\n\n![crystal ball](crystal-ball.jpg)\n\n[oracles.cash](https://www.oracles.cash) is a platform for creating Oracles on Bitcoin Cash.\n\nOracles allow outside information to be provided which can trigger execution in smart-contracts. Oracles.cash is a template for easily spinning up a backend to publish oracle data as well as an example of a Bitcoin Cash smart-contract which consumes data from the oracle service.\n\nOracles can be used for:\n\n- Prediction markets\n- trustless gambling\n- Covenants\n\nOracles.cash was created by [@cgcardona](https://twitter.com/cgcardona) for the [2019 WyoHackathon](https://wyohackathon.io)\n\nMore info at [https://oracle.bitcoin.com/](https://oracle.bitcoin.com/)\n\n## Price Data\n\n`/v1/price/details` returns a data object with 4 properties.\n\n- `price`: USD price in cents\n- `height`: block height\n- `message` is a byte sequence of 8 bytes encoded as a hex string. The first 4 bytes are the blockheight and the 2nd 4 bytes are USD price in cents. The price is fetched from [Bitcoin.com's price index](https://index-api.bitcoin.com/api/v0/cash/price/usd)\n- `signature` is the message signed by an ECPair.\n\n```\ncurl -X GET \"http://localhost:3000/v1/price/details\" -H \"accept: application/json\"\n\n{\n  \"price\": 30350,\n  \"height\": 601406,\n  \"message\": \"3e2d09008e760000\",\n  \"signature\": \"304502210082180bc9cc4a4e41a5fe8b6c04d5c0d47d6a3174b3c0f3b7694550ad2bc72bbb02202250e01c018a760b30593ad9b71f1b6e0b0192c44183c4d38b0bdbc9f9edd3fd\"\n}\n```\n\n## Smart contract\n\nThis contract forces HODLing until a certain price target has been reached\nA minimum block is provided to ensure that oracle price entries from before this block are disregarded\ni.e. when the BCH price was \\$1000 in the past, an oracle entry with the old block number and price can not be used.\nInstead, a message with a block number and price from after the minBlock needs to be passed.\nThis contract serves as a simple example for checkDataSig-based contracts.\n\nCredit to [Rosco Khalis](https://twitter.com/RoscoKalis), creator of CashScript, for creating the HodlVault Cash Contract.\n\n`./src/routes/v1/contracts/hodl_vault.cash`\n`./hodl_vault.ts`\n\n### Fund the contract\n\nFirst, take note of the following line in `hold_vault.ts`\n\n```ts\nconst instance: Instance = HodlVault.new(\n  bitbox.ECPair.toPublicKey(owner),\n  bitbox.ECPair.toPublicKey(oracle.keypair),\n  597000,\n  30000\n)\n```\n\nThat is the line where you instantiate the contract. the 3rd arg is the blockheight and the 4th arg is the USD price in cents.\n\nThose values will matter later when you want to spend the funds which are locked in this contract. You'll need to pass in a blockheight and price which are greater than what you pass in when you instantiate the contract.\n\nComment out the following lines in `hold_vault.ts`\n\n```ts\n// Produce new oracle message and signature\nconst oracleMessage: Buffer = oracle.createMessage(597000, 30000)\nconst oracleSignature: Buffer = oracle.signMessage(oracleMessage)\n\n// Spend from the vault\nconst tx: TxnDetailsResult = await instance.functions\n  .spend(new Sig(owner, 0x01), oracleSignature, oracleMessage)\n  .send(instance.address, 1000)\n```\n\nThen run the script using [ts-node](https://www.npmjs.com/package/ts-node)\n\n```\n./node_modules/.bin/ts-node ./hodl_vault.ts\ncontract address: bchtest:pr6a369a5s3k5fqfnkhnnjw2a0rq6rkrkgvaqy7g7l\ncontract balance: 0\n```\n\nNotice it displays the contracts P2SH (pay-to-script-hash) address. Send some funds to that address where they will be locked.\n\n### Spend the contract\n\nNow you're ready to spend the funds which are locked in the contract. To do that first uncomment out the lines which we commented out in the previous step:\n\n```ts\n// Produce new oracle message and signature\nconst oracleMessage: Buffer = oracle.createMessage(597000, 30000)\nconst oracleSignature: Buffer = oracle.signMessage(oracleMessage)\n\n// Spend from the vault\nconst tx: TxnDetailsResult = await instance.functions\n  .spend(new Sig(owner, 0x01), oracleSignature, oracleMessage)\n  .send(instance.address, 1000)\n```\n\nNext update the following line to have a valid block height and BCH price\n\n```ts\nconst oracleMessage: Buffer = oracle.createMessage(597000, 30000)\n```\n\nKeep in mind that the blockheight and price must be greater than what you passed in when you instantiated the contract.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitcoin-com%2Foracles.cash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitcoin-com%2Foracles.cash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitcoin-com%2Foracles.cash/lists"}