Skip to content

Commit fab08ed

Browse files
authored
feat: adding new abi-typegen package (#570)
1 parent 25449bd commit fab08ed

File tree

226 files changed

+5138
-7638
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

226 files changed

+5138
-7638
lines changed

.changeset/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
}
88
],
99
"commit": false,
10-
"fixed": [["@fuel-ts/*", "fuels", "typechain-target-fuels", "fuelchain"]],
10+
"fixed": [["@fuel-ts/*", "fuels"]],
1111
"linked": [],
1212
"access": "public",
1313
"baseBranch": "master",

.changeset/ten-students-dress.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@fuel-ts/abi-typegen": minor
3+
"@fuel-ts/contract": minor
4+
"@fuel-ts/example-contract": minor
5+
"fuels": minor
6+
---
7+
8+
Replace `fuelchain` and `typechain-target-fuels` with `abi-typegen`

.eslintignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
.hbs
12
node_modules/
23
coverage/
34
dist/
45
packages/example-contract/src/example-contract-types
5-
packages/typechain-target-fuels/static
6-
packages/typechain-target-fuels/example
76
packages/providers/src/__generated__
87
out
98
CHANGELOG.md
109

1110
# Docs files
1211
_includes/js/custom.js
13-
docs/examples/
12+
docs/examples/

.prettierignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
*.hbs
2+
13
dist
24
.coverage_*
35
coverage
46
node_modules
57
docs/examples/
68
/packages/example-contract/src/example-contract-types/
7-
/packages/typechain-target-fuels/static/
8-
/packages/typechain-target-fuels/example/
9+
910
__generated__
1011
out
1112
CHANGELOG.md

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"recommendations": [
33
"orta.vscode-jest",
44
"esbenp.prettier-vscode",
5-
"dbaeumer.vscode-eslint"
5+
"dbaeumer.vscode-eslint",
6+
"ionutvmi.path-autocomplete"
67
]
78
}

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,16 @@
1818
},
1919
"[json]": {
2020
"editor.defaultFormatter": "esbenp.prettier-vscode"
21+
},
22+
"[handlebars]": {
23+
"editor.formatOnSave": false,
24+
"editor.formatOnPaste": false
25+
},
26+
"path-autocomplete.includeExtension": true,
27+
"path-autocomplete.extensionOnImport": true,
28+
"path-autocomplete.excludedItems": {
29+
// do not mess with defaut auto-complete for `js` and `ts`
30+
"**/*.ts": { "when": "**" },
31+
"**/*.js": { "when": "**" }
2132
}
2233
}

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
- [Import](#import)
1919
- [Calling Contracts](https://fuellabs.github.io/fuels-ts/guide/calling-contracts)
2020
- [Generate Contract Types from ABI](https://fuellabs.github.io/fuels-ts/guide/contracts/generate-contract-types-from-abi)
21-
- [Dependencies](#dependencies)
2221
- [Using Generated Types](https://fuellabs.github.io/fuels-ts/guide/types/using-generated-types)
2322
- [Deploying Contracts](https://fuellabs.github.io/fuels-ts/guide/contracts/deploying-contracts)
2423
- [CLI](/#CLI)
@@ -83,12 +82,13 @@ $ yarn exec fuels -h
8382
Usage: fuels [options] [command]
8483

8584
Options:
86-
-V, --version output the version number
87-
-h, --help display help for command
85+
-V, --version output the version number
86+
-h, --help display help for command
8887

8988
Commands:
90-
versions checks for version incompatibilities
91-
help [command] display help for command
89+
versions check for version incompatibilities
90+
typegen [options] generate typescript from contract abi json files
91+
help [command] display help for command
9292
```
9393

9494
## License

docs/QUICKSTART.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ Notice an important thing here; The **`Contract id`** is the address of the depl
299299
Now we are going to;
300300

301301
1. **Initialize a React project.**
302-
2. **Install the `fuels` SDK dependencies.**
302+
2. **Install the `fuels` SDK.**
303303
3. **Modify the App.**
304304
4. **Run our project.**
305305

@@ -315,13 +315,9 @@ npx create-react-app frontend --template typescript
315315

316316
The command will generate a react app using [`Create React App`](https://create-react-app.dev/).
317317

318-
#### 4.2 Install the `fuels` SDK dependencies.
318+
#### 4.2 Install the `fuels` SDK
319319

320-
On this step we need to install 3 dependencies for the project:
321-
322-
1. `fuels`: The umbrella package that includes all the main tools; `Wallet`, `Contracts`, `Providers` and more.
323-
2. `fuelchain`: Fuelchain is the ABI TypeScript generator.
324-
3. `typechain-target-fuels`: The Fuelchain Target is the specific interpreter for the [Fuel ABI Spec](https://github.com/FuelLabs/fuel-specs/blob/master/specs/protocol/abi.md).
320+
Now we install the `fuels` umbrella package that includes all the main tools; all the classes such as `Wallet`, `Contracts`, `Providers` and more. Also, it is our utility for ABI TypeScript generation.
325321

326322
> ABI stands for Application Binary Interface. ABI's inform the application the interface to interact with the VM, in other words, they provide info to the APP such as what methods a contract has, what params, types it expects, etc...
327323
@@ -331,26 +327,32 @@ Inside `my-fuel-dapp/frontend` run;
331327

332328
```sh
333329
npm install fuels --save
334-
npm install fuelchain typechain-target-fuels --save-dev
335330
```
336331

337332
##### Generating contract types
338333

339-
To make it easier to interact with our contract we use `fuelchain` to interpret the output ABI JSON from our contract. This JSON was created on the moment we executed the `forc build` to compile our Sway Contract into binary. If you see the folder `my-fuel-dapp/contract/out` you will be able to see the ABI JSON there. If you want to learn more, read the [ABI Specs here](https://github.com/FuelLabs/fuel-specs/blob/master/specs/protocol/abi.md).
334+
To make it easier to interact with our contract we use `fuels typegen` to interpret the output ABI JSON from our contract. This JSON was created on the moment we executed the `forc build` to compile our Sway Contract into binary. If you see the folder `my-fuel-dapp/contract/out` you will be able to see the ABI JSON there. If you want to learn more, read the [ABI Specs here](https://github.com/FuelLabs/fuel-specs/blob/master/specs/protocol/abi.md).
340335

341336
Inside `my-fuel-dapp/frontend` run;
342337

343338
```sh
344-
npx fuelchain --target=fuels --out-dir=./src/contracts ../contract/out/debug/*-abi.json
339+
npx fuels typegen -i ../contract/out/debug/*-abi.json -o ./src/contracts
345340
```
346341

347342
You should see something like this:
348343

349344
```sh
350-
Successfully generated 4 typings!
345+
$ npx fuels typegen -i ../counter-contract/out/debug/*-abi.json -o ./src/contracts
346+
Generating files..
347+
348+
- src/contracts/ContractAbi.d.ts
349+
- src/contracts/factories/ContractAbi__factory.ts
350+
- src/contracts/index.ts
351+
352+
Done.⚡
351353
```
352354

353-
Now you should be able to find a new folder `my-fuel-dapp/frontend/src/contracts`. This folder was auto-generated by our `fuelchain` command, this files abstract the work we would need to do, to create a contract instance, and also generate a complete TypeScript interface to the Contract, making easy to develop.
355+
Now you should be able to find a new folder `my-fuel-dapp/frontend/src/contracts`. This folder was auto-generated by our `fuels typegen` command, this files abstract the work we would need to do, to create a contract instance, and also generate a complete TypeScript interface to the Contract, making easy to develop.
354356

355357
### 3. Modify the App.
356358

@@ -364,7 +366,7 @@ import React, { useEffect, useState } from "react";
364366
import { Wallet } from "fuels";
365367
import "./App.css";
366368

367-
// Import the contract factory from the folder generated by the fuelchain
369+
// Import the contract factory from the folder generated by the `fuels typegen`
368370
// command
369371
import { ContractAbi__factory } from "./contracts";
370372

docs/_guide/abi-typegen/generate-contract-types-from-abi.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ See also [types](../types/).
77
#### Dependencies
88

99
```sh
10-
yarn add -D fuelchain typechain-target-fuels
10+
yarn add fuels
1111
```
1212

1313
#### Generate Types
1414

1515
```sh
16-
yarn exec fuelchain --target=fuels --out-dir=types abi.json
16+
yarn exec fuels -i ./abis/*-abi.json -o ./types
1717
```
1818

1919
Note:
2020

21-
- `target`: will always be `fuels`
22-
- `out-dir`: the output directory for the generated types
23-
- `abi.json`: the relative path to the JSON file for the ABI
21+
- `-i`: the relative path/global to the ABI JSON file(s)
22+
- `-o`: the output directory for the generated types

docs/guide/abi-typegen/generate-contract-types-from-abi.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@ See also [types](../types/).
1515
#### Dependencies
1616

1717
```sh
18-
yarn add -D fuelchain typechain-target-fuels
18+
yarn add fuels
1919
```
2020

2121
#### Generate Types
2222

2323
```sh
24-
yarn exec fuelchain --target=fuels --out-dir=types abi.json
24+
yarn exec fuels -i ./abis/*-abi.json -o ./types
2525
```
2626

2727
Note:
2828

29-
- `target`: will always be `fuels`
30-
- `out-dir`: the output directory for the generated types
31-
- `abi.json`: the relative path to the JSON file for the ABI
29+
- `-i`: the relative path/global to the ABI JSON file(s)
30+
- `-o`: the output directory for the generated types

0 commit comments

Comments
 (0)