{"id":27801443,"url":"https://github.com/nirvanush/ergoscript-nodejs","last_synced_at":"2025-05-01T05:01:48.634Z","repository":{"id":53861616,"uuid":"521727374","full_name":"nirvanush/ergoscript-nodejs","owner":"nirvanush","description":null,"archived":false,"fork":false,"pushed_at":"2022-08-05T17:48:53.000Z","size":369,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-19T21:23:08.466Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/nirvanush.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}},"created_at":"2022-08-05T17:42:24.000Z","updated_at":"2022-08-05T17:46:16.000Z","dependencies_parsed_at":"2022-08-23T16:30:50.297Z","dependency_job_id":null,"html_url":"https://github.com/nirvanush/ergoscript-nodejs","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/nirvanush%2Fergoscript-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nirvanush%2Fergoscript-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nirvanush%2Fergoscript-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nirvanush%2Fergoscript-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nirvanush","download_url":"https://codeload.github.com/nirvanush/ergoscript-nodejs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251758162,"owners_count":21638989,"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":"2025-05-01T05:01:12.470Z","updated_at":"2025-05-01T05:01:48.619Z","avatar_url":"https://github.com/nirvanush.png","language":"TypeScript","funding_links":[],"categories":["🛠️ Development Tooling \u003ca id=\"development-tooling\"\u003e\u003c/a\u003e"],"sub_categories":["📜 Smart Contracts \u0026 ErgoScript \u003ca id=\"smart-contracts--ergoscript\"\u003e\u003c/a\u003e"],"readme":"---\n\n# Ergoscript nodejs build with ergo-lib-wasm-nodejs\n\n[![npm package][npm-img]][npm-url]\n[![Build Status][build-img]][build-url]\n[![Issues][issues-img]][issues-url]\n[![Commitizen Friendly][commitizen-img]][commitizen-url]\n[![Semantic Release][semantic-release-img]][semantic-release-url]\n\n## Install\n\n```bash\nnpm install ergoscript-nodejs\n```\n\n## Usage\n\n### Basic transaction to send token\n\n```ts\nconst tx = new Transaction([\n  {\n    funds: {\n      ERG: 100000,\n      tokens: [{ tokenId: 'token id', amount: '1' }],\n    },\n    toAddress: 'address',\n    additionalRegisters: {},\n  },\n]);\n\nconst unsignedTx = (await tx.build()).toJSON();\n\n// using ergo wallet\nconst signedTx = await ergo.sign_tx(unsignedTx);\nawait ergo.submit_tx(signedTx);\n```\n\n### Multiple recipients / airdrop \n\n```ts\nconst tokenId = '\u003ctokenId\u003e'\nconst recipients = [\n  { address: '\u003caddress_1\u003e', amount: 1 },\n  { address: '\u003caddress_2\u003e', amount: 10 },\n  { address: '\u003caddress_3\u003e', amount: 100 },\n  { address: '\u003caddress_4\u003e', amount: 1000 }\n]\n\nconst tx = new Transaction(recipients.map(rec =\u003e {\n  return {\n    funds: {\n      ERG: 100000,\n      tokens: [{ tokenId, amount: rec.amount }],\n    },\n    toAddress: rec.address,\n    additionalRegisters: {\n      R4: { value: 40, type: 'Int' }\n    },\n  }\n}));\n\nconst unsignedTx = (await tx.build()).toJSON();\n\n// using ergo wallet\nconst signedTx = await ergo.sign_tx(unsignedTx);\nawait ergo.submit_tx(signedTx);\n```\n\n### Immutability\n\n```ts\n// Methods return a new instance instead of modifying the old instance\nconst INPUT_0 = new eUTXOBox(tokenToRent as ExplorerBox);\n\n// modify ergoTree value\nconst OUTPUT_0 = INPUT_0.sendTo(changeAddress);\nOUTPUT_0.ergoTree !== INPUT_0.ergoTree;\n\n// setRegisters - add registers and return new instance\nconst INPUT_0 = new eUTXOBox(tokenToRent as ExplorerBox);\nconst OUTPUT_0 = INPUT_0.setRegisters({\n  R5: { value: price, type: Long },\n  R6: { value: period, type: Long },\n});\n\nconst tx = new Transaction([\n  [INPUT_0, OUTPUT_0], // setting those boxes as first input and output of the transaction - handy for smart contracts\n  {\n    funds: {\n      ERG: 100000,\n      tokens: [{ tokenId: 'token id', amount: '1' }],\n    },\n    toAddress: 'address',\n    additionalRegisters: {},\n  },\n]);\n\n// reset registers - remove all registers and return new instance\nconst OUTPUT_0 = INPUT_0.resetRegisters();\n```\n\n### Test script with Mocha test\n\n```ts\nimport buildScriptScope from 'ergoscript/lib/ergoscriptMock';\n\nconst script = `sigmaProp(true)`;\n\nconst tx = new Transaction([\n  {\n    funds: {\n      ERG: 100000,\n      tokens: [{ tokenId: 'token id', amount: '1' }],\n    },\n    toAddress: 'address',\n    additionalRegisters: {},\n  },\n]);\n\ndescribe('Rentring transaction', () =\u003e {\n  it('reduces to true', async () =\u003e {\n    const txBuilt = await tx.build();\n\n    const simulator = await buildScriptScope(txBuilt);\n    const response = simulator.execute(script);\n\n    expect(response).to.be.true;\n  });\n});\n```\n\n[build-img]: https://github.com/nirvanush/ergoscript/actions/workflows/release.yml/badge.svg\n[build-url]: https://github.com/nirvanush/ergoscript/actions/workflows/release.yml\n[npm-img]: https://img.shields.io/npm/v/ergoscript\n[npm-url]: https://www.npmjs.com/package/ergoscript\n[issues-img]: https://img.shields.io/github/issues/nirvanush/ergoscript\n[issues-url]: https://github.com/nirvanush/ergoscript/issues\n[semantic-release-img]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg\n[semantic-release-url]: https://github.com/semantic-release/semantic-release\n[commitizen-img]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg\n[commitizen-url]: http://commitizen.github.io/cz-cli/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnirvanush%2Fergoscript-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnirvanush%2Fergoscript-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnirvanush%2Fergoscript-nodejs/lists"}