{"id":17939407,"url":"https://github.com/libitx/manic","last_synced_at":"2025-07-13T09:34:14.255Z","repository":{"id":57520601,"uuid":"257909159","full_name":"libitx/manic","owner":"libitx","description":"Manic is an Elixir client for interfacing with Bitcoin miner APIs.","archived":false,"fork":false,"pushed_at":"2023-08-03T18:52:22.000Z","size":114,"stargazers_count":10,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-27T21:38:43.641Z","etag":null,"topics":["bitcoin","bsv","elixir","merchant-api"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/manic","language":"Elixir","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/libitx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-22T13:26:18.000Z","updated_at":"2022-01-17T15:44:09.000Z","dependencies_parsed_at":"2022-09-26T18:01:02.581Z","dependency_job_id":null,"html_url":"https://github.com/libitx/manic","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/libitx/manic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libitx%2Fmanic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libitx%2Fmanic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libitx%2Fmanic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libitx%2Fmanic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libitx","download_url":"https://codeload.github.com/libitx/manic/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libitx%2Fmanic/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265120476,"owners_count":23714490,"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":["bitcoin","bsv","elixir","merchant-api"],"created_at":"2024-10-29T00:07:11.667Z","updated_at":"2025-07-13T09:34:14.239Z","avatar_url":"https://github.com/libitx.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Manic\n\n![Manic is an Elixir client for interfacing with Bitcoin miner APIs.](https://github.com/libitx/manic/raw/master/media/poster.png)\n\n![Hex.pm](https://img.shields.io/hexpm/v/manic?color=informational)\n![GitHub](https://img.shields.io/github/license/libitx/manic?color=informational)\n![GitHub Workflow Status](https://img.shields.io/github/workflow/status/libitx/manic/Elixir%20CI)\n\nManic is an Elixir client for interfacing with Bitcoin miner APIs.\n\nManic is a port of [unwriter's](https://twitter.com/_unwriter) [Minercraft](https://minercraft.network) library for JavaScript. Like Minercraft, Manic supports the [beta version of the Merchant API](https://bitcoinsv.io/2020/04/03/miner-id-and-merchant-api-beta-release/), and its name is a nod to another classic computer game.\n\n## Features\n\nManic supports the following features:\n\n* Get dynamic fee rates from miners\n* Calculate the fee for any transaction\n* Push transactions directly to miners\n* Get the status of any transaction from miners\n* Automatically verifies the JSON Envelope signatures\n\n| Implemented spec | BRFC |\n| ---------------- | ---- |\n| [Merchant API Specification](https://github.com/bitcoin-sv-specs/brfc-merchantapi) | `ce852c4c2cd1` |\n| [Fee Specification](https://github.com/bitcoin-sv-specs/brfc-misc/tree/master/feespec) | `fb567267440a` |\n| [JSON Envelope Specification](https://github.com/bitcoin-sv-specs/brfc-misc/tree/master/jsonenvelope) | `298e080a4598` |\n\n## Installation\n\nThe package can be installed by adding `manic` to your list of dependencies\nin `mix.exs`.\n\n```elixir\ndef deps do\n  [\n    {:manic, \"~\u003e 0.1\"}\n  ]\nend\n```\n\n## Usage\n\nFor detailed examples, refer to the [full documentation](https://hexdocs.pm/manic).\n\n### 1. Initalize a miner client\n\nInitialize a miner client with the full URL of the Merchant API endpoint.\n\n```elixir\niex\u003e miner = Manic.miner \"https://merchantapi.taal.com\"\n%Tesla.Client{}\n```\n\nA client can aslo be initialized using any of the keys from a list of known miners. Additional headers can also be specified if necessary.\n\n```elixir\niex\u003e miner = Manic.miner :mempool, headers: [{\"token\", token}]\n%Tesla.Client{}\n```\n\n### 2. Get and calculate fees\n\nThe miner client can then be used to query the miner's up-to-date fee rates.\n\n```elixir\niex\u003e Manic.Fees.get(miner)\n{:ok, %{\n  expires: ~U[2020-04-20 16:35:03.168Z],\n  mine: %{data: 0.5, standard: 0.5},\n  relay: %{data: 0.25, standard: 0.25},\n  verified: true\n}}\n```\n\nThe fee for a transaction can be calculated using the given rates.\n\n```elixir\niex\u003e Manic.Fees.calculate(rates.mine, tx)\n{:ok, 346}\n```\n\n### 3. Push and query transactions\n\nManic can be used to push transactions directly to the miner.\n\n```elixir\niex\u003e Manic.TX.push(miner, tx)\n{:ok, %{\n  \"api_version\" =\u003e \"0.1.0\",\n  \"current_highest_block_hash\" =\u003e \"00000000000000000397a5a37c1f9b409b4b58e76fd6bcac06db1a3004cccb38\",\n  \"current_highest_block_height\" =\u003e 631603,\n  \"miner_id\" =\u003e \"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270\",\n  \"result_description\" =\u003e \"\",\n  \"return_result\" =\u003e \"success\",\n  \"timestamp\" =\u003e \"2020-04-21T14:04:39.563Z\",\n  \"tx_second_mempool_expiry\" =\u003e 0,\n  \"txid\" =\u003e \"9c8c5cf37f4ad1a82891ff647b13ec968f3ccb44af2d9deaa205b03ab70a81fa\",\n  \"verified\" =\u003e true\n}}\n```\n\nAny transaction's status can be queried by its `txid`.\n\n```elixir\niex\u003e Manic.TX.status(miner, \"e4763d71925c2ac11a4de0b971164b099dbdb67221f03756fc79708d53b8800e\")\n{:ok, %{\n  \"api_version\" =\u003e \"0.1.0\",\n  \"block_hash\" =\u003e \"000000000000000000983dee680071d63939f4690a8a797c022eddadc88f925e\",\n  \"block_height\" =\u003e 630712,\n  \"confirmations\" =\u003e 765,\n  \"miner_id\" =\u003e \"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270\",\n  \"result_description\" =\u003e \"\",\n  \"return_result\" =\u003e \"success\",\n  \"timestamp\" =\u003e \"2020-04-20T21:45:38.808Z\",\n  \"tx_second_mempool_expiry\" =\u003e 0,\n  \"verified\" =\u003e true\n}}\n```\n\n## Multi miners\n\nIn the examples above, each API function is invoked by passing a single miner client. Manic also provides a way of interacting with multiple miner clients concurrently, and yielding the response from any or all of the miners.\n\n### 1. Initalize a multi-miner client\n\nInitialize a multi miner client with a list of miner Merchant API endpoint details. The list can contain either a full URL, a key from the list of known miners, or a tuple pair containing any additional options.\n\n```elixir\niex\u003e Manic.multi([\n...\u003e   \"https://merchantapi.taal.com\",\n...\u003e   :matterpool,\n...\u003e   {:mempool, headers: [{\"token\", token}]}\n...\u003e ])\n%Manic.Multi{}\n```\n\n### 2. Push a tx an any miner\n\nBy default, multi miner requests will yield until **any** of the miners responds. This is allows a transaction to be pushed to multiple miners concurrently, and return a response when the first response is recieved.\n\n```elixir\niex\u003e Manic.multi(miners)\n...\u003e |\u003e Manic.TX.push(tx)\n{^miner, {:ok, %{\n  \"api_version\" =\u003e \"0.1.0\",\n  \"current_highest_block_hash\" =\u003e \"00000000000000000397a5a37c1f9b409b4b58e76fd6bcac06db1a3004cccb38\",\n  \"current_highest_block_height\" =\u003e 631603,\n  \"miner_id\" =\u003e \"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270\",\n  \"result_description\" =\u003e \"\",\n  \"return_result\" =\u003e \"success\",\n  \"timestamp\" =\u003e \"2020-04-21T14:04:39.563Z\",\n  \"tx_second_mempool_expiry\" =\u003e 0,\n  \"txid\" =\u003e \"9c8c5cf37f4ad1a82891ff647b13ec968f3ccb44af2d9deaa205b03ab70a81fa\",\n  \"verified\" =\u003e true\n}}}\n```\n\n### 3. Query all miners concurrently\n\nAlternatively, a multi miner client can be initialized with the option `yield: :all` which awaits **all** miner clients to respond before returning the list of responses. This allows us to compare fees from multiple miners concurrently.\n\n```elixir\niex\u003e Manic.multi(miners, yield: :all)\n...\u003e |\u003e Manic.Fees.get\n[\n  {^miner, {:ok, %{\n    expires: ~U[2020-04-20 16:35:03.168Z],\n    mine: %{data: 0.5, standard: 0.5},\n    relay: %{data: 0.25, standard: 0.25},\n    verified: true\n  }}},\n  {^miner, {:ok, %{\n    expires: ~U[2020-04-20 16:35:03.168Z],\n    mine: %{data: 0.5, standard: 0.5},\n    relay: %{data: 0.25, standard: 0.25},\n    verified: true\n  }}},\n  {^miner, {:ok, %{\n    expires: ~U[2020-04-20 16:35:03.168Z],\n    mine: %{data: 0.5, standard: 0.5},\n    relay: %{data: 0.25, standard: 0.25},\n    verified: true\n  }}}\n]\n```\n\nFor more examples, refer to the [full documentation](https://hexdocs.pm/manic).\n\n## License\n\n[MIT License](https://github.com/libitx/manic/blob/master/LICENSE.md).\n\n© Copyright 2020 libitx.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibitx%2Fmanic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibitx%2Fmanic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibitx%2Fmanic/lists"}