{"id":27801442,"url":"https://github.com/nirvanush/ergoscript","last_synced_at":"2025-05-01T05:01:48.991Z","repository":{"id":49438768,"uuid":"499620041","full_name":"nirvanush/ergoscript","owner":"nirvanush","description":"ergo transaction builder optimized for contract development","archived":false,"fork":false,"pushed_at":"2022-08-05T17:30:49.000Z","size":926,"stargazers_count":9,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-07T16:08:49.559Z","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-06-03T18:56:15.000Z","updated_at":"2022-10-24T18:33:26.000Z","dependencies_parsed_at":"2022-09-06T01:30:22.358Z","dependency_job_id":null,"html_url":"https://github.com/nirvanush/ergoscript","commit_stats":null,"previous_names":["nirvanush/ergoscript.js"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nirvanush%2Fergoscript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nirvanush%2Fergoscript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nirvanush%2Fergoscript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nirvanush%2Fergoscript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nirvanush","download_url":"https://codeload.github.com/nirvanush/ergoscript/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251672568,"owners_count":21625514,"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.336Z","updated_at":"2025-05-01T05:01:48.923Z","avatar_url":"https://github.com/nirvanush.png","language":"TypeScript","readme":"---\n\n# Ergoscriptjs\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\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  }\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","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"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnirvanush%2Fergoscript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnirvanush%2Fergoscript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnirvanush%2Fergoscript/lists"}