{"id":18405690,"url":"https://github.com/bitcoinjs/coinselect","last_synced_at":"2025-04-12T23:29:18.436Z","repository":{"id":5337956,"uuid":"42842035","full_name":"bitcoinjs/coinselect","owner":"bitcoinjs","description":"An unspent transaction output (UTXO) selection module for bitcoin.","archived":false,"fork":false,"pushed_at":"2023-10-20T03:18:25.000Z","size":206,"stargazers_count":189,"open_issues_count":24,"forks_count":107,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-04T02:08:30.536Z","etag":null,"topics":["bitcoin","change","coin","selection","unspents","utxos","wallet"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/bitcoinjs.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":"2015-09-21T03:35:19.000Z","updated_at":"2025-03-30T00:42:09.000Z","dependencies_parsed_at":"2024-06-18T12:35:37.582Z","dependency_job_id":null,"html_url":"https://github.com/bitcoinjs/coinselect","commit_stats":{"total_commits":191,"total_committers":8,"mean_commits":23.875,"dds":"0.16753926701570676","last_synced_commit":"1f7cd3766e2c891909a4d72afb472b54b70fc239"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitcoinjs%2Fcoinselect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitcoinjs%2Fcoinselect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitcoinjs%2Fcoinselect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitcoinjs%2Fcoinselect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitcoinjs","download_url":"https://codeload.github.com/bitcoinjs/coinselect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248646707,"owners_count":21139051,"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","change","coin","selection","unspents","utxos","wallet"],"created_at":"2024-11-06T03:03:38.529Z","updated_at":"2025-04-12T23:29:18.412Z","avatar_url":"https://github.com/bitcoinjs.png","language":"JavaScript","readme":"# coinselect\n\n[![TRAVIS](https://secure.travis-ci.org/bitcoinjs/coinselect.png)](http://travis-ci.org/bitcoinjs/coinselect)\n[![NPM](http://img.shields.io/npm/v/coinselect.svg)](https://www.npmjs.org/package/coinselect)\n\n[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n\nAn unspent transaction output (UTXO) selection module for bitcoin.\n\n**WARNING:** Value units are in `satoshi`s, **not** Bitcoin.\n\n\n## Algorithms\nModule | Algorithm | Re-orders UTXOs?\n-|-|-\n`require('coinselect')` | Blackjack, with Accumulative fallback | By Descending Value\n`require('coinselect/accumulative')` | Accumulative - accumulates inputs until the target value (+fees) is reached, skipping detrimental inputs | -\n`require('coinselect/blackjack')` | Blackjack - accumulates inputs until the target value (+fees) is matched, does not accumulate inputs that go over the target value (within a threshold) | -\n`require('coinselect/break')` | Break - breaks the input values into equal denominations of `output` (as provided) | -\n`require('coinselect/split')` | Split - splits the input values evenly between all `outputs`, any provided `output` with `.value` remains unchanged | -\n\n\n**Note:** Each algorithm will add a change output if the `input - output - fee` value difference is over a dust threshold.\nThis is calculated independently by `utils.finalize`, irrespective of the algorithm chosen, for the purposes of safety.\n\n**Pro-tip:** if you want to send-all inputs to an output address, `coinselect/split` with a partial output (`.address` defined, no `.value`) can be used to send-all, while leaving an appropriate amount for the `fee`. \n\n## Example\n\n``` javascript\nlet coinSelect = require('coinselect')\nlet feeRate = 55 // satoshis per byte\nlet utxos = [\n  ...,\n  {\n    txId: '...',\n    vout: 0,\n    ...,\n    value: 10000,\n    // For use with PSBT:\n    // not needed for coinSelect, but will be passed on to inputs later\n    nonWitnessUtxo: Buffer.from('...full raw hex of txId tx...', 'hex'),\n    // OR\n    // if your utxo is a segwit output, you can use witnessUtxo instead\n    witnessUtxo: {\n      script: Buffer.from('... scriptPubkey hex...', 'hex'),\n      value: 10000 // 0.0001 BTC and is the exact same as the value above\n    }\n  }\n]\nlet targets = [\n  ...,\n  {\n    address: '1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm',\n    value: 5000\n  }\n]\n\n// ...\nlet { inputs, outputs, fee } = coinSelect(utxos, targets, feeRate)\n\n// the accumulated fee is always returned for analysis\nconsole.log(fee)\n\n// .inputs and .outputs will be undefined if no solution was found\nif (!inputs || !outputs) return\n\nlet psbt = new bitcoin.Psbt()\n\ninputs.forEach(input =\u003e\n  psbt.addInput({\n    hash: input.txId,\n    index: input.vout,\n    nonWitnessUtxo: input.nonWitnessUtxo,\n    // OR (not both)\n    witnessUtxo: input.witnessUtxo,\n  })\n)\noutputs.forEach(output =\u003e {\n  // watch out, outputs may have been added that you need to provide\n  // an output address/script for\n  if (!output.address) {\n    output.address = wallet.getChangeAddress()\n    wallet.nextChangeAddress()\n  }\n\n  psbt.addOutput({\n    address: output.address,\n    value: output.value,\n  })\n})\n```\n\n\n## License [MIT](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitcoinjs%2Fcoinselect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitcoinjs%2Fcoinselect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitcoinjs%2Fcoinselect/lists"}