Cannot "npx fuels typegen" my contract

When I build empty dapp like counter it worked well, but with my contract I keep getting this error

my contract:
fuel-token-standard/main.sw at master · sway-gang/fuel-token-standard · GitHub

command line
npx fuels typegen -i ../contract/out/debug/*-abi.json -o ./src/contracts

output

 npx fuels typegen -i ../contract/out/debug/*-abi.json -o ./src/contracts/Users/lidia/projects/my-fuel-dapp/frontend/node_modules/@fuel-ts/abi-typegen/dist/cli.js:96`;function It(n){let{name:r,rawContents:t}=n.abi,e=JSON.stringify(t,null,2);return A({template:Tt,data:{capitalizedName:r,abiJsonString:e}})}var dt=W(require("lodash.upperfirst"));function gt(n){let t=[e=>e.replace(/\s+/g,"-"),e=>e.replace(/\./g,"-"),e=>e.replace(/_/g,"-"),e=>e.replace(/-[a-z]/g,i=>i.slice(-1).toUpperCase()),e=>e.replace(/-/g,""),e=>e.replace(/^\d+/,""),e=>(0,dt.default)(e)].reduce((e,i)=>i(e),n);if(t==="")throw new Error(`Can't guess class name, please rename file: ${n}`);return t}function T(n){let{types:r,typeId:t}=n,e=r.find(({rawAbiType:{typeId:i}})=>i===t);if(!e)throw new Error(`Type ID not found: ${t}.`);return e.parseComponentsAttributes({types:r}),e}function I(n){let{types:r,typeArguments:t,parentTypeId:e,target:i}=n,s=`${i}Label`,a=[],o,m;e!==void 0&&(o=T({types:r,typeId:e}),m=o.attributes[s]),t.forEach(y=>{let l=y.type,f=T({types:r,typeId:l}).attributes[s];if(y.typeArguments){let g=I({types:r,target:i,parentTypeId:y.type,typeArguments:y.typeArguments});a.push(g)}else a.push(`${f}`)});let u=a.join(", ");return m&&(u=`${m}<${u}>`),u}var V=class{constructor(r){this.types=r.types,this.rawAbiFunction=r.rawAbiFunction,this.attributes={name:this.rawAbiFunction.name,inputs:this.bundleInputTypes(),output:this.bundleOutputTypes(),prefixedInputs:this.bundleInputTypes(!0)}}bundleInputTypes(r=!1){let{types:t}=this;return this.rawAbiFunction.inputs.map(i=>{let{name:s,type:a,typeArguments:o}=i,m=T({types:t,typeId:a}),u;return o?u=I({types:t,target:"input",parentTypeId:a,typeArguments:o}):u=m.attributes.inputLabel,r?`${s}: ${u}`:u}).join(", ")}bundleOutputTypes(){return I({types:this.types,target:"output",typeArguments:[this.rawAbiFunction.output]})}getDeclaration(){let{name:r,prefixedInputs:t,output:e}=this.attributes;return`${r}: InvokeFunction<[${t}], ${e}>`}};function ht(n){let{types:r,rawAbiFunction:t}=n;return new V({types:r,rawAbiFunction:t})}function At(n){let{types:r,rawAbiFunctions:t}=n;return t.map(i=>ht({types:r,rawAbiFunction:i}))}var b=class{constructor(r){this.rawAbiType=r.rawAbiType,this.attributes={inputLabel:"unknown",outputLabel:"unknown"}}};var z=class extends b{constructor(){super(...arguments);this.name="array"}static isSuitableFor(t){return z.MATCH_REGEX.test(t.type)}parseComponentsAttributes(t){var y,l;let{types:e}=t,{type:i}=this.rawAbiType,s=Number((y=i.match(z.MATCH_REGEX))==null?void 0:y[1]),a=[],o=[];(l=this.rawAbiType.components)==null||l.forEach(c=>{let{type:f,typeArguments:g}=c;if(g){let h=I({types:e,typeArguments:g,parentTypeId:f,target:"input"}),F=I({types:e,typeArguments:g,parentTypeId:f,target:"output"});a.push(h),o.push(F)}else{let{attributes:h}=T({types:e,typeId:f});a.push(h.inputLabel),o.push(h.outputLabel)}});let m=Array(s).fill(a[0]).join(", "),u=Array(s).fill(o[0]).join(", ");return this.attributes={inputLabel:`[${m}]`,outputLabel:`[${u}]`},this.attributes}},E=z;E.swayType="[_; 2]",E.MATCH_REGEX=/^\[_; ([0-9]+)\]$/m;var tt=class extends b{constructor(){super(...arguments);this.name="str"}static isSuitableFor(t){return tt.MATCH_REGEX.test(t.type)}parseComponentsAttributes(t){return this.attributes={inputLabel:"string",outputLabel:"string"},this.attributes}},w=tt;w.swayType="str[3]",w.MATCH_REGEX=/^str\[(.+)\]$/m;var et=class extends w{constructor(){super(...arguments);this.name="b256"}static isSuitableFor(t){return et.MATCH_REGEX.test(t.type)}},R=et;R.swayType="b256",R.MATCH_REGEX=/^b256$/m;var rt=class extends R{constructor(){super(...arguments);this.name="b512"}static isSuitableFor(t){return rt.MATCH_REGEX.test(t.type)}},L=rt;L.swayType="b512",L.MATCH_REGEX=/^b512$/m;var it=class extends b{constructor(){super(...arguments);this.name="bool"}static isSuitableFor(t){return it.MATCH_REGEX.test(t.type)}parseComponentsAttributes(t){return this.attributes={inputLabel:"boolean",outputLabel:"boolean"},this.attributes}},S=it;S.swayType="bool",S.MATCH_REGEX=/^bool$/m;function G(n){var i;let{rawAbiType:r,regex:t}=n,e=(i=r.type.match(n.regex))==null?void 0:i[1];if(!e){let s=`Couldn't extract struct name with: '${t}'.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ^

Error: Type ID not found: 0.
    at T (/Users/lidia/projects/my-fuel-dapp/frontend/node_modules/@fuel-ts/abi-typegen/dist/cli.js:96:598)
    at /Users/lidia/projects/my-fuel-dapp/frontend/node_modules/@fuel-ts/abi-typegen/dist/cli.js:96:861
    at Array.forEach (<anonymous>)
    at I (/Users/lidia/projects/my-fuel-dapp/frontend/node_modules/@fuel-ts/abi-typegen/dist/cli.js:96:834)
    at V.bundleOutputTypes (/Users/lidia/projects/my-fuel-dapp/frontend/node_modules/@fuel-ts/abi-typegen/dist/cli.js:96:1609)
    at new V (/Users/lidia/projects/my-fuel-dapp/frontend/node_modules/@fuel-ts/abi-typegen/dist/cli.js:96:1248)
    at ht (/Users/lidia/projects/my-fuel-dapp/frontend/node_modules/@fuel-ts/abi-typegen/dist/cli.js:96:1860)
    at /Users/lidia/projects/my-fuel-dapp/frontend/node_modules/@fuel-ts/abi-typegen/dist/cli.js:96:1958
    at Array.map (<anonymous>)
    at At (/Users/lidia/projects/my-fuel-dapp/frontend/node_modules/@fuel-ts/abi-typegen/dist/cli.js:96:1951)

fuels version: ^0.0.0-next-20221215155703

Is there something wrong with my contract?

2 Likes

Hey! Is this to generate the types in your frontend? If so, it looks like you’re using an old version.

The updated quickstart is here and includes the correct command to generate types.

Here is the command: npx fuelchain --target=fuels --out-dir=./src/contracts ../<name-of-project-here>/out/debug/*-abi.json

btw love the repo name.

@camiinthisthang.sway Actually, this is the new command; the fuelchain is the old one.

@sway Your contract looks ok, it seems you might have hit a new issue.

Please track it here:

1 Like

Wow, that’s pretty professional community building