Skip to content
Merged
Show file tree
Hide file tree
Changes from 116 commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
5698534
Adjusting interface and typings for `loggedTypes` ABI property
arboleya Jan 19, 2023
6bb183a
Exporting all interfaces on package index
arboleya Jan 19, 2023
9569380
Adding new dependency
arboleya Jan 19, 2023
6a21da2
Drafting `ScriptWrapper` class
arboleya Jan 19, 2023
af6a7b8
Adding new enum
arboleya Jan 19, 2023
431185d
Individualizing file’s assemblers for Contract and Script
arboleya Jan 19, 2023
567062a
Improving regex
arboleya Jan 22, 2023
11ec5b6
Trimming non-essential bridges, sub-methods should be used directly
arboleya Jan 22, 2023
8e7fd02
Configuring new options for Typegen CLI; updating programmatic API
arboleya Jan 22, 2023
ce1ebd7
Drafting initial templates for Scripts
arboleya Jan 22, 2023
f5c9850
Updating lock file
arboleya Jan 22, 2023
65d50bd
Rendering templates directly
arboleya Jan 22, 2023
7ae14fb
Start using standalone file assemblers
arboleya Jan 22, 2023
7cca75f
Merge branch 'master' into aa/feat/script-abi-typegen
arboleya Jan 22, 2023
ce87784
Untangling variables from the main `Abi` class
arboleya Jan 22, 2023
dcf7223
Adding changeset
arboleya Jan 22, 2023
a371db3
Externalizing shared testing utility
arboleya Jan 23, 2023
bf45f0c
Refactoring test, deleting unrelated parts from old implementation
arboleya Jan 23, 2023
4d36174
Tyop
arboleya Jan 23, 2023
e9f7025
Implementing tests for newly added file assemblers
arboleya Jan 23, 2023
31bd761
Temporarily hard-coding place-holder data for templates
arboleya Jan 23, 2023
c10dfde
Adding test stubs
arboleya Jan 23, 2023
6afa35f
Improving CLI options, validating conflicting parameters
arboleya Jan 24, 2023
35bfc30
Tyop
arboleya Jan 24, 2023
0654739
Removing extra conditional, reducing case scenarios
arboleya Jan 24, 2023
570d468
Refactoring existent CLI tests and adding missing ones
arboleya Jan 24, 2023
4f848bb
Adding missing test for `AbiTypegen`
arboleya Jan 24, 2023
0194767
Drafting template rendering test, adding TODOs
arboleya Jan 24, 2023
cad9eca
Remodeling function interfaces
arboleya Jan 24, 2023
0253092
Tyop
arboleya Jan 24, 2023
d998dc2
Fixing template
arboleya Jan 24, 2023
50eee28
Adding placeholder code for reading script `bin` file from disk
arboleya Jan 24, 2023
bd52bb4
Switching variable class name to `ScriptFactory`
arboleya Jan 24, 2023
49b246e
Fixing script factory renderer method, gathering prop definitions
arboleya Jan 24, 2023
fd5ba8c
Adding missing import to template
arboleya Jan 24, 2023
bae23f4
Adjusting test fixture
arboleya Jan 24, 2023
d85b30c
Improving test helper, adding extra options
arboleya Jan 24, 2023
c3d518f
Adjusting missing test case
arboleya Jan 24, 2023
e02a372
Removing log call
arboleya Jan 24, 2023
69ed225
Fixing test, dealing with mocked instances’ state
arboleya Jan 24, 2023
3765c9a
Removing duplicates, moving templates around
arboleya Jan 24, 2023
fe5d2bb
Lintfix
arboleya Jan 24, 2023
3871de1
Tidying up, lint fixing, spell checking, remodeling directory structure
arboleya Jan 24, 2023
f91127f
Improving test validations, checking for parameters incompatibility
arboleya Jan 24, 2023
b7ddc50
Docs
arboleya Jan 24, 2023
d5bb2df
Fixing scripts URL for Sway docs
arboleya Jan 24, 2023
ebf77f7
Removing extraneous configs
arboleya Jan 24, 2023
515cb99
Updating help usage, fixing tyop
arboleya Jan 24, 2023
06f51c3
Removing useless options
arboleya Jan 24, 2023
ee6b41b
Purging dead code
arboleya Jan 24, 2023
debc9d3
Removing temporary draft / placeholder
arboleya Jan 24, 2023
5840c8c
Fixing template; updating test fixture to match
arboleya Jan 24, 2023
1fa9f46
Merge branch 'master' into aa/feat/script-abi-typegen
arboleya Jan 25, 2023
51863bf
Merge branch 'master' into aa/feat/script-abi-typegen
arboleya Feb 1, 2023
d5cb1b7
Extracting code chunks into separate utilities
arboleya Feb 2, 2023
d3e5cf3
Adding `@ethersproject/bytes` to the mix
arboleya Feb 2, 2023
6f5627c
Updating script/factory template, adjusting data format and rendering
arboleya Feb 2, 2023
2359d18
Adding new validation utility
arboleya Feb 2, 2023
6f8535a
Start handling BIN files alongside their ABI counterparts
arboleya Feb 2, 2023
7ec043d
Adding test stubs/placeholders
arboleya Feb 2, 2023
4a5399d
Adjusting virtual filename for Script in tests
arboleya Feb 2, 2023
7568660
Updating template fixture
arboleya Feb 2, 2023
f74f65e
Temporarily skipping broken tests, adding TODOs
arboleya Feb 2, 2023
980e741
Improving test utility, adding options required for dealing w/ Scripts
arboleya Feb 2, 2023
7baa1f6
Resolving TODOs, fixing and un-skipping broken tests
arboleya Feb 2, 2023
c64545d
Adding new Sway Script test fixture
arboleya Feb 2, 2023
7d70f86
Narrowing Script conditional
arboleya Feb 2, 2023
b1fe166
Updating error message
arboleya Feb 2, 2023
ad0a8c9
Making parameter required
arboleya Feb 2, 2023
7cfe832
Adding missing test cases; stressing errors related to Scripts
arboleya Feb 2, 2023
5817051
Resolving TODO, using Sway script sample, fixing ABI instantiation
arboleya Feb 2, 2023
d7631e0
Updating rendered template fixture
arboleya Feb 2, 2023
dcc38c7
Removing useless conditional
arboleya Feb 3, 2023
4c086d3
Fine-tuning new utility, adding tests
arboleya Feb 3, 2023
d0f85d6
Removing needless type definitions; improving auto-complete
arboleya Feb 3, 2023
4894ee9
Implementing tests for new template utilities
arboleya Feb 3, 2023
49dd990
Renaming files and updating their references
arboleya Feb 3, 2023
ce81949
Renaming files and updating their references, again
arboleya Feb 3, 2023
710cc80
Adding new property to Abi classes
arboleya Feb 3, 2023
922d93f
Adjusting index template, adding exception for Contracts
arboleya Feb 3, 2023
dc51d04
Adjusting Script factory template
arboleya Feb 3, 2023
6b16903
Fixing usages of Abi class; updating constructor signature
arboleya Feb 3, 2023
241af51
Merge branch 'master' into aa/feat/script-abi-typegen
arboleya Feb 7, 2023
ba81ac3
Merge branch 'master' into aa/feat/script-abi-typegen
arboleya Feb 9, 2023
508b41a
Improving test for Script factory template
arboleya Feb 9, 2023
573721e
Merge branch 'master' into aa/feat/script-abi-typegen
arboleya Feb 21, 2023
17665ae
Merge branch 'master' into aa/feat/script-abi-typegen
arboleya Feb 23, 2023
5f33bcb
Adding new flag to denote items that need to be imported from `fuels`
arboleya Feb 23, 2023
56748d1
Updating tests for all types
arboleya Feb 23, 2023
ddc8a44
Adding new template utility
arboleya Feb 23, 2023
b4e3447
Improving array sorting by running it in a case-insensitive manner
arboleya Feb 23, 2023
1cba768
Adding `lodash.uniq` to the mix
arboleya Feb 23, 2023
03e0940
Updating Contract `dts` template, render, and tests
arboleya Feb 23, 2023
a1980ea
Updating Script `factory` template, render, and tests
arboleya Feb 23, 2023
a86dfa9
Fixing broken test
arboleya Feb 23, 2023
7245b92
Tyop
arboleya Feb 23, 2023
77bf91f
Updating docs on programmatic usage
arboleya Feb 23, 2023
818f129
Merge branch 'master' of github.com:FuelLabs/fuels-ts into aa/feat/sc…
arboleya Feb 23, 2023
f7ff311
Adjusting enum CASE
arboleya Feb 23, 2023
51b3005
Merge branch 'master' into aa/feat/script-abi-typegen
arboleya Feb 23, 2023
9fb3077
Docs
arboleya Feb 23, 2023
a8a9dc0
Merge branch 'aa/feat/script-abi-typegen' of github.com:FuelLabs/fuel…
arboleya Feb 23, 2023
bfe1450
Merge branch 'master' into aa/feat/script-abi-typegen
arboleya Feb 23, 2023
c4075fd
Updating fixture utility
arboleya Feb 24, 2023
a3dabc1
Restoring mocks before assertions
arboleya Feb 24, 2023
1f220ef
Updating Sway script fixture
arboleya Feb 24, 2023
8ef07b9
Returning additional property.
arboleya Feb 24, 2023
171f230
DRY; considering [hexlified] bin files
arboleya Feb 24, 2023
2feed02
Updating sub-method signature; expanding outputs
arboleya Feb 24, 2023
672f91d
Renaming method
arboleya Feb 24, 2023
e7a6970
Renaming file to match inner method
arboleya Feb 24, 2023
57b71f0
Merge branch 'master' of github.com:FuelLabs/fuels-ts into aa/feat/sc…
arboleya Feb 24, 2023
5ebe886
Lintfix
arboleya Feb 24, 2023
4d5f0cf
Merge branch 'master' into aa/feat/script-abi-typegen
arboleya Feb 24, 2023
274ce42
Merge branch 'master' into aa/feat/script-abi-typegen
arboleya Feb 28, 2023
ebeba26
Merge branch 'master' into aa/feat/script-abi-typegen
arboleya Mar 3, 2023
0bb6adf
Merge branch 'master' into aa/feat/script-abi-typegen
arboleya Mar 7, 2023
fc55b61
Renaming enum, updating refs
arboleya Mar 7, 2023
d6aaa04
Adjusting semantics of category x programType in more places
arboleya Mar 7, 2023
6cd300d
Dedupe; adding correct link to related doc section
arboleya Mar 7, 2023
8abe9c1
Adjusting link
arboleya Mar 7, 2023
695f221
Docs; updating nomenclatures on `packages/abi-typegen` README
arboleya Mar 7, 2023
342b43c
Docs, adjusting links again
arboleya Mar 7, 2023
d1dac3d
Reality check, exorcizing code smells
arboleya Mar 7, 2023
834a7ef
Merge branch 'master' into aa/feat/script-abi-typegen
arboleya Mar 7, 2023
7af22b9
Merge branch 'master' into aa/feat/script-abi-typegen
arboleya Mar 7, 2023
c327b03
Merge branch 'master' into aa/feat/script-abi-typegen
arboleya Mar 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wicked-files-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/abi-typegen": minor
---

Adding support for generating types from Script ABIs
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- [Install](#install)
- [Import](#import)
- [Interacting with Contracts](https://fuellabs.github.io/fuels-ts/guide/contracts/interacting-with-contracts.html)
- [Generate Contract Types from ABI](https://fuellabs.github.io/fuels-ts/guide/abi-typegen/generate-contract-types-from-abi.html)
- [Generate Types from ABI](https://fuellabs.github.io/fuels-ts/guide/abi-typegen/generating-types-from-abi.html)
- [Using Generated Types](https://fuellabs.github.io/fuels-ts/guide/abi-typegen/using-generated-types.html)
- [Deploying Contracts](https://fuellabs.github.io/fuels-ts/guide/contracts/deploying-contracts)
- [CLI](#cli)
Expand Down
22 changes: 0 additions & 22 deletions docs/_guide/abi-typegen/generate-contract-types-from-abi.md

This file was deleted.

64 changes: 64 additions & 0 deletions docs/_guide/abi-typegen/generating-types-from-abi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[nav_order: 0]

# Generating Types from ABI

## Installation

First we install `fuels` to our project:

```sh
yarn add fuels
```

## Help

A first glance at the docs:

```console
$ yarn exec fuels typegen -h

Usage: fuels typegen [options]

generate typescript from contract abi json files

Options:
-i, --inputs <path|glob... input paths/globals to your abi json files
-o, --output <dir> directory path for generated files
-c, --contract generate code for contracts [default]
-s, --script generate code for scripts
--silent omit output messages
-h, --help display help for command
```

## Generating Types for Contracts

We can omit the `--contract` option here; its the default:

```console
yarn exec fuels -i ./abis/*-abi.json -o ./types
```

**Notes**

- `-i`: the relative path/global to the ABI JSON file(s)
- `-o`: the output directory for the generated types
- `-c, --contract`: tells we want to generate types for contracts _(default, can be omitted)_

## Generating Types for Scripts

Note how we make use of the option `--script` in this case:

```console
yarn exec fuels -i ./abis/*-abi.json -o ./types --script
```

**Notes**

- `-s, --script`: Tells we want to generate types for scripts

---

See also:

- [Using Generated Contract Types](./using-generated-types.md#using-generated-contract-types)
- [Using Generated Script Types](./using-generated-types.md#using-generated-script-types)
13 changes: 9 additions & 4 deletions docs/_guide/abi-typegen/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

## The JSON ABI file

Whether you want to deploy or connect to a pre-existing smart contract, the JSON ABI file is extremely important: it's what tells the SDK about the [ABI methods](https://fuellabs.github.io/sway/v{{site.data.versions.sway}}/book/introduction/sway_quickstart.html?highlight=abi#abi) in your smart contracts.
Whether you want to deploy or connect to a pre-existing smart contract, the [JSON ABI](https://fuellabs.github.io/sway/v{{site.data.versions.sway}}/book/introduction/sway_quickstart.html?highlight=abi#abi) file is what makes it possible.

For the same example Sway code as above:
It tells the SDK about the [ABI methods](https://fuellabs.github.io/sway/v{{site.data.versions.sway}}/book/introduction/sway_quickstart.html?highlight=abi#abi) in your [Smart Contracts](https://fuellabs.github.io/sway/vv{{site.data.versions.sway}}/book/sway-program-types/smart_contracts.html) and [Scripts](https://fuellabs.github.io/sway/vv{{site.data.versions.sway}}/book/sway-program-types/scripts.html).

Given the following Sway smart contract:

```rust
contract;
Expand All @@ -22,7 +24,7 @@ impl MyContract for Contract {
}
```

The JSON ABI file looks like this:
The JSON ABI file would look something like this:

```json
$ cat out/debug/my-test-abi.json
Expand All @@ -42,4 +44,7 @@ $ cat out/debug/my-test-abi.json
]
```

The Fuel TypeScript SDK will take this file as input and generate equivalent methods (and custom types if applicable) that you can call from your TypeScript code.
See also:

- [Generating Contract Types](./generating-types-from-abi.md)
- [Generating Contract Types](./generating-types-from-abi.md)
40 changes: 37 additions & 3 deletions docs/_guide/abi-typegen/using-generated-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,51 @@

# Using Generated Types

See also [Generate Contract Types from ABI](./generate-contract-types-from-abi.md).
After generating types via:

```console
yarn exec fuels -i ./abis/*-abi.json -o ./types
```

We can use these files like so:

```ts
import { Wallet } from "fuels";
import { MyContract__factory } from "./types";

const contractId = "0x...";
const wallet = new Wallet("0x...");
const wallet = Wallet.fromAddress("...");
const contract = MyContract__factory.connect(contractId, wallet);

// All contract methods are available under functions with the correct types
const { transactionId, value } = await contract.functions.my_fn(1n).call();
const { transactionId, value } = await contract.functions.my_fn(1).call();

console.log(transactionId, value);
```

# Using Generated Script Types

After generating types via:

```console
yarn exec fuels -i ./abis/*-abi.json -o ./types --script
```

We can use these files like so:

```ts
import { Wallet } from "fuels";
import { MyScript__factory } from "./types";

const wallet = Wallet.fromAddress("...");
const script = ScriptAbi__factory.createInstance(wallet);

const { value, logs } = await script.functions.main(1).call();

console.log({ value, logs });
```

See also:

- [Generating Types for Contracts](./generating-types-from-abi.md#generating-types-for-contracts)
- [Generating Types for Scripts](./generating-types-from-abi.md#generating-types-for-scripts)
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const config: Config.InitialOptions = {
coveragePathIgnorePatterns: ['/dist/', '/test/', '.test.ts', '.d.ts'],
testTimeout: 15000,
transform: {
'\\.hbs': 'jest-text-transformer',
'\\.hbs$': 'jest-text-transformer',
},
};

Expand Down
18 changes: 11 additions & 7 deletions packages/abi-typegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ npm add @fuel-ts/abi-typegen

```console
$ fuels-typegen -h
Usage: fuels-typegen -i ../out/*-abi.json -o ./generated/
Usage: fuels-typegen [options]

generate typescript from contract abi json files

Options:
-V, --version output the version number
-i, --inputs <path|glob...> input paths/globals to your abi json files
-o, --output <dir> directory path for generated files
-s, --silent omit output messages
-c, --contract generate types for contracts [default]
-s, --script generate types for scripts
--silent omit output messages
-h, --help display help for command
```

Expand All @@ -49,21 +52,22 @@ When using the package in a standalone fashion, its bin is prefixed with `fuels-
npx fuels-typegen -i ./out/debug/*-abi.json -o ./src/contracts
```

## Programatic API
## Programmatic API

```ts
import { runTypegen } from "@fuel-ts/abi-typegen";
import { CategoryEnum, runTypegen } from "@fuel-ts/abi-typegen";

const cwd = process.cwd();
const input = './abis/**-abi.json'
const output = './types'
const filepaths = [ './abis/a-abi.json', './abis/b-abi.json' ]
const category = CategoryEnum.CONTRACT;

// using input global
await runTypegen({ cwd, input, output });
await runTypegen({ cwd, input, output, category });

// using filepaths' array
await runTypegen({ cwd, filepaths, output });
await runTypegen({ cwd, filepaths, output, category });
}
```

Expand Down
3 changes: 3 additions & 0 deletions packages/abi-typegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@
],
"license": "Apache-2.0",
"dependencies": {
"@ethersproject/bytes": "^5.7.0",
"@fuel-ts/versions": "workspace:*",
"commander": "^9.4.1",
"glob": "^8.0.3",
"handlebars": "^4.7.7",
"lodash.uniq": "^4.5.0",
"lodash.upperfirst": "^4.3.1",
"mkdirp": "^1.0.4",
"rimraf": "^3.0.2"
},
"devDependencies": {
"@types/glob": "^8.0.0",
"@types/lodash.uniq": "^4.5.7",
"@types/lodash.upperfirst": "^4.3.7",
"@types/mkdirp": "^1.0.2",
"@types/rimraf": "^3.0.2",
Expand Down
Loading