{"id":29100435,"url":"https://github.com/zianksm/smartcontract-type-binding-generator","last_synced_at":"2026-04-30T02:31:54.612Z","repository":{"id":65384875,"uuid":"554688339","full_name":"zianksm/smartcontract-type-binding-generator","owner":"zianksm","description":"ethereum smart contract bindings code generator","archived":false,"fork":false,"pushed_at":"2022-12-27T05:59:49.000Z","size":80,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-05T15:52:29.498Z","etag":null,"topics":["code-generation","javascript","parser","truffle","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/smartcontract-type-binding-generator","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zianksm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-20T08:14:12.000Z","updated_at":"2023-02-13T14:18:29.000Z","dependencies_parsed_at":"2023-01-31T02:45:43.100Z","dependency_job_id":null,"html_url":"https://github.com/zianksm/smartcontract-type-binding-generator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zianksm/smartcontract-type-binding-generator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zianksm%2Fsmartcontract-type-binding-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zianksm%2Fsmartcontract-type-binding-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zianksm%2Fsmartcontract-type-binding-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zianksm%2Fsmartcontract-type-binding-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zianksm","download_url":"https://codeload.github.com/zianksm/smartcontract-type-binding-generator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zianksm%2Fsmartcontract-type-binding-generator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32452292,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T22:27:22.272Z","status":"online","status_checked_at":"2026-04-30T02:00:05.929Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["code-generation","javascript","parser","truffle","typescript"],"created_at":"2025-06-28T18:14:05.894Z","updated_at":"2026-04-30T02:31:54.580Z","avatar_url":"https://github.com/zianksm.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Type Bindings Generator For Smart Contract\n\nThis tool aim to ease web3 developers pains when dealing with smart contracts on the blockchain. it provides type inference\ngenerated from contract's abi. this tool generate a contract class wrapper intended to be used alongside [ethers](https://www.npmjs.com/package/ethers). this tool also can generate `javascript` and [truffle](https://www.npmjs.com/package/truffle) bindings used for testing purposes.  \n\nMind you that, this tool only support inferring function return types for constant function call to solidity contracts only. That is, function call that does not change the state of the blockchain. Any non-constant function calls will have their return types inferred as `any`.\n\n## How it works\nIt basically tries to infer function parameter and return types based on abi solidity types that resolve to corresponding `Javascript/Typescript` Types.\n\n| Solidity           | Javascript/Typescript |\n|--------------------|-----------------------|\n| int                | ethers.BigNumber      |\n| uint               | ethers.BigNumber      |\n| address            | string                |\n| string             | string                |\n| bool               | boolean               |\n\nTypes that are not listed in the table above will be inferred as `any` types.\n\ndue to solidity having integer types that are outside of the safe range javascript/typescript `number` types operates on, any integer type regardless of the bit size will be converted to a `BigNumber` instance by ethers.\n\n## Usage Example\n```typescript\nimport { Writer } from \"smartcontract-type-binding-generator\";\n\nconst abi = fs.readFileSync(\"some-abi.json\");\nconst writer = new Writer();\nconst options = {\n  lang: \"js\",\n  truffle: false,\n}\n\nconst output = writer.write(\"yourCotnractName\", abi.toString(),options);\n\nfs.writeFileSync(\"./output.js\",output);\n```\n## Typescript Output Example\n```typescript\nimport * as ethers from \"ethers\"\n\nexport class yourCotnractName {\n  private contractInstance: ethers.Contract\n  public contractAddress: string\n\n  constructor(contractAddress: string, abi: any, signerOrProvider?: ethers.ethers.Signer | ethers.ethers.providers.Provider) {\n    this.contractInstance = new ethers.Contract(contractAddress, abi, signerOrProvider);\n    this.contractAddress = contractAddress;\n  }\n\n  public async DEFAULT_ADMIN_ROLE(): Promise\u003cany\u003e  {\n    const tx = await this.contractInstance.DEFAULT_ADMIN_ROLE();\n    return tx;\n  }\n\n  public async MINTER_ROLE(): Promise\u003cany\u003e  {\n    const tx = await this.contractInstance.MINTER_ROLE();\n    return tx;\n  }\n\n  public async PAUSER_ROLE(): Promise\u003cany\u003e  {\n    const tx = await this.contractInstance.PAUSER_ROLE();\n    return tx;\n  }\n\n  public async balanceOf (account: string, id: number) : Promise\u003cethers.BigNumber\u003e  {\n    const tx = await this.contractInstance.balanceOf(account,id);\n    return tx;\n  }\n}\n```\n\n## Javascript Output Example\n```javascript\nconst ethers = require(\"ethers\");\n\nclass yourCotnractName {\n  contractInstance\n  contractAddress\n\n  /**\n   * \n   * @param {string} contractAddress \n   * @param {any} abi \n   * @param {ethers.Signer | ethers.providers | undefined} signerOrProvider \n   */\n  constructor(contractAddress, abi, signerOrProvider = undefined) {\n    this.contractInstance = new ethers.Contract(contractAddress, abi, signerOrProvider);\n    this.contractAddress = contractAddress;\n  }\n  /**\n   * @returns {any}\n   */\n  async DEFAULT_ADMIN_ROLE() {\n    const tx = await this.contractInstance.DEFAULT_ADMIN_ROLE();\n    return tx;\n  }\n\n  /**\n   * @returns {any}\n   */\n  async MINTER_ROLE() {\n    const tx = await this.contractInstance.MINTER_ROLE();\n    return tx;\n  }\n\n  /**\n   * @returns {any}\n   */\n  async PAUSER_ROLE() {\n    const tx = await this.contractInstance.PAUSER_ROLE();\n    return tx;\n  }\n\n  /**\n   * @param {string} account\n   * @param {number} id\n   * @returns {ethers.BigNumber}\n   */\n  async balanceOf(account, id) {\n    const tx = await this.contractInstance.balanceOf(account, id);\n    return tx;\n  }\n}\n```\n\n## Javascript with truffle support ouput example\nWith the truffle support set to `true`, it will provide a parameter to change `msg.sender` value. the parameter will be generated for all method regardless function types. \n```javascript\nconst ethers = require(\"ethers\");\n\nclass yourContractName {\n  contractInstance\n  contractAddress\n\n  /**\n   * \n   * @param {string} contractAddress \n   * @param {any} abi \n   * @param {ethers.Signer | ethers.providers | undefined} signerOrProvider \n   */\n  constructor(contractAddress, abi, signerOrProvider = undefined) {\n    this.contractInstance = new ethers.Contract(contractAddress, abi, signerOrProvider);\n    this.contractAddress = contractAddress;\n  }\n  /**\n   * @returns {any}\n   */\n  async DEFAULT_ADMIN_ROLE(fromAddress) {\n    const tx = await this.contractInstance.DEFAULT_ADMIN_ROLE({ from: fromAddress });\n    return tx;\n  }\n\n  /**\n   * @returns {any}\n   */\n  async MINTER_ROLE(fromAddress) {\n    const tx = await this.contractInstance.MINTER_ROLE({ from: fromAddress });\n    return tx;\n  }\n\n  /**\n   * @returns {any}\n   */\n  async PAUSER_ROLE(fromAddress) {\n    const tx = await this.contractInstance.PAUSER_ROLE({ from: fromAddress });\n    return tx;\n  }\n\n  /**\n   * @param {string} account\n   * @param {number} id\n   * @returns {ethers.BigNumber}\n   */\n  async balanceOf(account, id, fromAddress) {\n    const tx = await this.contractInstance.balanceOf(account, id, { from: fromAddress });\n    return tx;\n  }\n\n```\n\n### There are several options available to determine what bindings to generate\n```typescript\ntype writerOtions =\n  | {\n      /**\n       * specify what bindings to generate (default `typescript`).\n       */\n      lang?: \"ts\";\n    }\n  | {\n      /**\n       * specify what bindings to generate (default `typescript`).\n       */\n      lang: \"js\";\n      /**\n       * generate `{from: address}` bindings for setting `msg.sender` value (useful building bindings for unit test using tools such as `truffle`).\n       *\n       * this option is only available if you specify `js` as the `bindings` lang to generate.\n       *\n       * default : `false`.\n       */\n      truffle?: boolean;\n    };\n```\n\n\n## Important\nMake sure to pass only the ABI's to the writer instance, as the `writer` instance only accepts array containing contracts abi.\n```json\n[\n  {\n    \"constant\": true,\n    \"inputs\": [],\n    \"name\": \"name\",\n    \"outputs\": [\n      {\n        \"name\": \"\",\n        \"type\": \"string\"\n      }\n    ],\n    \"payable\": false,\n    \"stateMutability\": \"view\",\n    \"type\": \"function\"\n  },\n  {\n    \"constant\": false,\n    \"inputs\": [\n      {\n        \"name\": \"_spender\",\n        \"type\": \"address\"\n      },\n      {\n        \"name\": \"_value\",\n        \"type\": \"uint256\"\n      }\n    ],\n    \"name\": \"approve\",\n    \"outputs\": [\n      {\n        \"name\": \"\",\n        \"type\": \"bool\"\n      }\n    ],\n    \"payable\": false,\n    \"stateMutability\": \"nonpayable\",\n    \"type\": \"function\"\n  }\n]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzianksm%2Fsmartcontract-type-binding-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzianksm%2Fsmartcontract-type-binding-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzianksm%2Fsmartcontract-type-binding-generator/lists"}