{"id":18557989,"url":"https://github.com/zh/bch-js-ext","last_synced_at":"2026-02-14T23:33:16.522Z","repository":{"id":66384496,"uuid":"300667911","full_name":"zh/bch-js-ext","owner":"zh","description":"Extensions to @psf/bch-js library","archived":false,"fork":false,"pushed_at":"2020-11-04T14:43:14.000Z","size":88,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-04T23:20:45.686Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/zh.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":"2020-10-02T16:04:06.000Z","updated_at":"2023-02-06T18:23:00.000Z","dependencies_parsed_at":"2023-02-27T18:00:25.503Z","dependency_job_id":null,"html_url":"https://github.com/zh/bch-js-ext","commit_stats":{"total_commits":7,"total_committers":1,"mean_commits":7.0,"dds":0.0,"last_synced_commit":"96228ecea0210a41a0bb4f2924376374a9c81368"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/zh/bch-js-ext","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zh%2Fbch-js-ext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zh%2Fbch-js-ext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zh%2Fbch-js-ext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zh%2Fbch-js-ext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zh","download_url":"https://codeload.github.com/zh/bch-js-ext/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zh%2Fbch-js-ext/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29460740,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T22:42:09.113Z","status":"ssl_error","status_checked_at":"2026-02-14T22:42:05.053Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-06T21:38:36.041Z","updated_at":"2026-02-14T23:33:16.506Z","avatar_url":"https://github.com/zh.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bch-js-ext\n\nExtensions to [PSF bch-js](https://github.com/Permissionless-Software-Foundation/bch-js) JavaScript library.\n\n`bch-js` is a great JavaScript library for working with Bitcoin Cash. The easiest way is to use it with the software stack provided by [FullStack.cash](https://fullstack.cash/).\nThe current library provides some extensions to `bch-js` like:\n\n- Some useful methods for getting detailed UTXO information (`Ext module`)\n- Easier transactions building (`TXBuilder module`)\n- Working with groups of NFTs (`NFT module`)\n\n## Usage\n\n- Install library: `npm install bch-js-ext`\n- Instantiate the library in your code:\n\n```js\nconst MAINNET_API = 'https://api.fullstack.cash/v3/'\nconst SLPDB_API = 'https://slpdb.fountainhead.cash/'\n\nconst BCHJSEXT = require('bch-js-ext')\nconst bchjs = new BCHJSEXT({\n  restURL: MAINNET_API,\n  slpdbURL: SLPDB_API,\n  apiToken: process.env.BCHJSTOKEN\n})\n```\n\nFor more detailed usage see the [examples directory](./examples) code.\n\n## Library methods\n\n### Ext module\n\nThese methods are used also in the other modules.\n\n* `validAddress(address)` - check if given **BCH** or **SLP** address is valid\n  * **address**: *String*. example: `'bitcoincash:eedddd...' or 'simpleledger:....'`\n  * **return**: *true/false*\n\n* `calculateFee(numInputs, numOutputs, satsPerByte)` - miner fee to pay for the transaction\n  * **numInputs**: *Integer*\n  * **numOutputs**: *Integer*\n  * **satsPerByte**: *Float*\n\n* `combineUtxos(outputs, utxos, amount, satsPerByte` - combine several UTXOs to pay for the transaction\n  * **outputs** - *Array* in format `[{out: 'bitcoincash:...', value: 1000}, ...]`\n  * **utxos** - *Array* of UTXOs (for result from `bchjs.Electrumx.utxo(address)`)\n  * **amount** - *Satoshi* (optional) Use this amount instead of combining outputs values\n  * **satsPerByte** - *Float* (optional) cost per byte in satoshis (*default: 1.1*)\n\n```js\n const outputs = [\n   { out: 'bitcoincash:dsffff...', value: 1000 },\n   { out: 'bitcoincash:dsffee...', value: 2000 }\n ]\n const data = await bchjs.Electrumx.utxo('bitcoincash:dsffff...')\n const utxos = data.utxos\n const { paymentUtxos, remainder } = await bchjs.Ext.combineUtxos(outputs, utxos)\n```\n\n* `findBiggestUtxo(utxos)` - find UTXO with biggest value in an Array of UTXOs\n  * **utxos**: *Array* of UTXO objects\n  * **return**: *UTXO object*\n\n```js\n const data = await bchjs.Electrumx.utxo('bitcoincash:dsffff...')\n const utxos = data.utxos\n const utxo = await bchjs.Ext.findBiggestUtxo(utxos)\n```\n* `findPaymentUtxo(address, amount = 0)` - using `findBiggestUtxo()` method above to find the UTXO with enough value in satoshis\n  * **address**: *String*. example: `'bitcoincash:eedddd...'\n  * **amount**: *Integer* (optional). If provided will check if UTXO have such amount of satoshis. If not provided will not check UTXO value at all\n\n```js\nconst paymentUtxo = await this.bchjs.Ext.findPaymentUtxo('bitcoincash:dsffff...')\n```\n\n* `getUtxoDetails(address)` - detailed information about UTXOs (`hydreted UTXOs`)\n  * **address**: *String*. example: `'bitcoincash:eedddd...'\n  * **return**: *Array* of hydrated UTXOs\n\n```js\nconst tokenUtxos = await bchjs.Ext.getUtxoDetails('bitcoincash:dsffff...')\n```\n\n* Get UTXOs with detailed information about **particular token** (specified by ID or ticker)\n  * `getTokenUtxos(address, tokenId, types = {})`\n  * `getTickerUtxos(address, ticker, types = {})`\n     * **address**: *String*. example: `'bitcoincash:eedddd...'\n     * **tokenId**: *String*. example: `'b34esadd...'`\n     * **ticker**: *String*. example: `'NFT_TOKEN'`\n     * **return**: *Array* of hydrated UTXOs\n\n* `filterTokenUtxos(utxos, prefix)` - filter Array of token UTXOs for ones, which **ticker starts** with *prefix*\n  * **utxos**: *Array* of hydrated UTXOs\n  * **return**: *Array* of hydrated UTXOs\n\n```js\nconst tokenUtxos = await bchjs.Ext.getUtxoDetails('bitcoincash:dsffff...')\nconst nameServiceUTXOs = await bchjs.Ext. filterTokenUtxos(tokenUtxos, '_ns.')\n```\n\n### TXBuilder module\n\nThese methods are used also in the NFT module.\n\nAttaching input and output UTXOs during transaction building contain a lot of boilerplate code.\nSpecially signing ot input adds a lot of similar code. This module trying to make transaction buildeing easier. *TODO: maybe replace with CashScript in the future*\n\n* `addSignedInputs(wif, inputs)` - add Array of input UTXOs and sign them\n  * **wif**: *String*. Private key (WIF) for signing. example: `'L4.....'`\n  * **inputs**: *Array* of `{ utxo: \u003cUTXO object\u003e, value: Integer }` objects. *value* is optional. if not provided - using UTXO value\n\n* `addOutputs (outputs)` - add array of output UTXOs (payment, remainder etc.)\n  * **outputs**: *Array* of `{ out: \u003caddress_or_script\u003e, value: Integer }` objects. *value* is optional. if not provided - using UTXO value\n\nExample (NFT group creation)\n\n```js\nconst paymentUtxo = await this.bchjs.Ext.findPaymentUtxo(account.address)\nconst remainder = paymentUtxo.value - (2 * DUST) - TX_FEE\nconst txBuilder = new this.bchjs.TXBuilder(this.bchjs)\nconst script = this.bchjs.SLP.NFT1.newNFTGroupOpReturn(mintConfig)\nconst outputs = [\n  { out: script }, // OUT#0 OP_RETURN\n  { out: legacyAddress, value: DUST }, // OUT#1 token\n  { out: legacyAddress, value: DUST }, // OUT#2 minting baton\n  { out: bchAddress, value: remainder } // OUT#3 remainder\n]\nconst inputs = [{ utxo: paymentUtxo }] // IN#0 pay\ntxBuilder.addSignedInputs(wif, inputs)\n```\n\nSee NFT examples in the [example directory](./examples/) for more detailed usage information.\n\n### NFT module\n\nMethods for easy Group/Children NFT non-fungible tokens operations - create, transfer, burn etc.\n\nAll of the methods have optional last parameter *send*:\n\n  * **true**: send the TX to the blockchain\n  * **false**: just create transaction HEX for inspection (**default**)\n\n*account* parameter used as a first parameter in most of the calls:\n\n```js\nconfig = {\n  address: 'bitcoincash: bdddfd....',\n  wif: 'L3.....'\n}\n```\n\n* `createGroup(account, config, send)` - create NFT group - can be used to create NFT children in the same group\n  * **account**: *Object* with address and private key.\n  * **config**: *Object* with token parameters. examples: `{ name: 'NFT NS', prefix: '_ns' }`, `{ name: 'TLD', ticker: '_ns.dom' }`\n\n```js\nconst groupNFT = {\n  name: 'Rare Items',\n  ticker: '_rare.items'\n}\nconst groupId = await bchjs.NFT.createGroup(account, groupNFT, true)\n```\n\nFor more information: [examples/nft_group.js](./examples/nft_group.js)\n\n* `createChild(account, config, send)` - create NFT child inside given NFT group\n  * **account**: *Object* with address and private key.\n  * **config**: *Object* with token parameters. examples: `{ group: 'b3sssdd...', name: 'CHLD1', prefix: '_uns' }`, `{ group: 'b3sssdd...', name: 'CHLD1', ticker: '_yns.bbb.aaaa' }`\n\n```js\nconst childNFT = {\n  group: 'dwgfdd...' // for example groupId in the example above\n  name: 'Very Rare Item #1',\n  ticker: '_item.tresure.one'\n}\nconst itemId = await bchjs.NFT.createChild(paymentAccount, childNFT, true)\n```\n\nFor more information: [examples/nft_child.js](./examples/nft_child.js)\n\n* `transferChild(account, config, toSlpAddress, send)` - transfer ownership of token to another account (simple token sending to SLP address)\n  * **account**: *Object* with address and private key.\n  * **config**: *Object* with token information. example: `{ id: 'b3sssdd...' }`, `{ ticker: '_uns.bbb.aaa' }`. Can even reuse NFT child creation config above.\n  * **toSlpAddress**: *String*. SLP address to send token to. example: `'simpleledger:ddsvs...'`\n\n```js\nconst config = { id: 'dsfsdf...' } // for example tokenId from the example above\nawait bchjs.NFT.transferChild(account, config, 'simpleledger:dfgdfggd...', true)\n```\n\nFor more information: [examples/nft_transfer.js](./examples/nft_transfer.js)\n\n* `removeChild(account, config, send)` - burn child NFT token\n  * **account**: *Object* with address and private key.\n  * **config**: *Object* with token information. example: `{ id: 'b3sssdd...' }`, `{ ticker: '_uns.bbb.aaa' }`. Can even reuse NFT child creation config above.\n\n```js\nconst config = { id: 'dsfsdf...' } // for example tokenId from the example above\nawait bchjs.NFT.removeChild(account, config, true)\n```\n\n* `findChildren(groupId)` - find all **non-burned NFT children** in a given group (created from the same group NFT token)\n  * **groupId**: *String*. token ID of the NFT group - for example groupId in the examples above\n  * **return**: *Array* of objects with token information (SLPDB response format)\n\n```js\nconst children = await bchjs.NFT.findChildren('dhdfhf...')\n```\n\n* `tokenAddresses(tokenId)` - return the SLP address, owning given NFT child token\n  * **tokenId**: *String*. token ID of the NFT child\n  * **return**: *String* - SLP address\n\n```js\nconst itemAddr = await bchjs.NFT.tokenAddresses('dhdfhf...')\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzh%2Fbch-js-ext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzh%2Fbch-js-ext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzh%2Fbch-js-ext/lists"}