Skip to content

Commit

Permalink
ci(changesets): versioning packages (#818)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Mar 9, 2023
1 parent f4e1028 commit f6948ff
Show file tree
Hide file tree
Showing 65 changed files with 534 additions and 110 deletions.
5 changes: 0 additions & 5 deletions .changeset/angry-peaches-count.md

This file was deleted.

4 changes: 0 additions & 4 deletions .changeset/purple-monkey-dishwashes.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/wicked-files-thank.md

This file was deleted.

30 changes: 0 additions & 30 deletions .changeset/young-gorillas-destroy.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/_data/versions.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated-file
fuels: 0.34.1
fuels: 0.35.0
fuel-core: 0.17.3
sway: 0.35.3
forc: 0.35.3
30 changes: 0 additions & 30 deletions docs/guide/abi-typegen/generate-contract-types-from-abi.md

This file was deleted.

77 changes: 77 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,77 @@
---
title: "Generating Types From Abi"
parent: "Abi Typegen"
grand_parent: "Guide"
nav_order: 0
---

[info]: this file is autogenerated


# 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
```

## Generating Types for Predicates

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

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

---

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)
- [Using Generated Predicate Types](./using-generated-types.md#using-generated-predicate-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 @@ -13,9 +13,11 @@ nav_order: 1

## 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 @@ -31,7 +33,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 @@ -51,4 +53,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 Types](./generating-types-from-abi.md)
- [Using Generated Types](./using-generated-types.md)
99 changes: 96 additions & 3 deletions docs/guide/abi-typegen/using-generated-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,112 @@ nav_order: 1
[info]: this file is autogenerated


<!-- TODO: Replace plan-text by code-snippets -->

# 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 });
```

# Using Generated Predicate Types

Consider the following predicate:


```rust
predicate;

struct Validation {
has_account: bool,
total_complete: u64,
}

fn main(received: Validation) -> bool {
let expected_has_account: bool = true;
let expected_total_complete: u64 = 100;

received.has_account == expected_has_account && received.total_complete == expected_total_complete
}
```
###### [see code in context](https://github.com/FuelLabs/fuels-ts/blob/master/packages/fuel-gauge/test-projects/predicate-main-args-struct/src/main.sw#L1-L15)

---


Now, after generating types via:

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

We can use these files like so:

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

const wallet = Wallet.fromAddress("...");
const predicate = MyPredicate__factory.createInstance();

await predicate
.setData({
has_account: true,
total_complete: 100,
})
.transfer(wallet.address, <amount>);

const walletBalance = await wallet.getBalance();
const predicateBalance = await predicate.getBalance();

console.log({
walletBalance,
predicateBalance,
});
```

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)
- [Generating Types for Predicates](./generating-types-from-abi.md#generating-types-for-predicates)
10 changes: 10 additions & 0 deletions packages/abi-coder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log

## 0.35.0

### Patch Changes

- [#819](https://github.com/FuelLabs/fuels-ts/pull/819) [`f4e1028a`](https://github.com/FuelLabs/fuels-ts/commit/f4e1028acd5a583d12662dd07ca0d17084a35be2) Thanks [@arboleya](https://github.com/arboleya)! - Adjusting export fields for all packages

- Updated dependencies [[`f4e1028a`](https://github.com/FuelLabs/fuels-ts/commit/f4e1028acd5a583d12662dd07ca0d17084a35be2)]:
- @fuel-ts/math@0.35.0
- @fuel-ts/versions@0.35.0

## 0.34.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/abi-coder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fuel-ts/abi-coder",
"version": "0.34.1",
"version": "0.35.0",
"description": "",
"author": "Fuel Labs <[email protected]> (https://fuel.network/)",
"typedoc": {
Expand Down
15 changes: 15 additions & 0 deletions packages/abi-typegen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# @fuel-ts/abi-typegen

## 0.35.0

### Minor Changes

- [#750](https://github.com/FuelLabs/fuels-ts/pull/750) [`84483d5d`](https://github.com/FuelLabs/fuels-ts/commit/84483d5d31ce3235ba40ff66ba257b2c9aa033cd) Thanks [@arboleya](https://github.com/arboleya)! - Adding support for generating types from Predicate ABIs

- [#747](https://github.com/FuelLabs/fuels-ts/pull/747) [`a424a8a7`](https://github.com/FuelLabs/fuels-ts/commit/a424a8a7d1151c9a9dc5a7fa4763ecfd1895de58) Thanks [@arboleya](https://github.com/arboleya)! - Adding support for generating types from Script ABIs

### Patch Changes

- [#819](https://github.com/FuelLabs/fuels-ts/pull/819) [`f4e1028a`](https://github.com/FuelLabs/fuels-ts/commit/f4e1028acd5a583d12662dd07ca0d17084a35be2) Thanks [@arboleya](https://github.com/arboleya)! - Adjusting export fields for all packages

- Updated dependencies [[`f4e1028a`](https://github.com/FuelLabs/fuels-ts/commit/f4e1028acd5a583d12662dd07ca0d17084a35be2)]:
- @fuel-ts/versions@0.35.0

## 0.34.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/abi-typegen/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fuel-ts/abi-typegen",
"version": "0.34.1",
"version": "0.35.0",
"description": "Generates Typescript definitions from Sway ABI Json files",
"author": "Fuel Labs <[email protected]> (https://fuel.network/)",
"typedoc": {
Expand Down
11 changes: 11 additions & 0 deletions packages/address/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change Log

## 0.35.0

### Patch Changes

- [#819](https://github.com/FuelLabs/fuels-ts/pull/819) [`f4e1028a`](https://github.com/FuelLabs/fuels-ts/commit/f4e1028acd5a583d12662dd07ca0d17084a35be2) Thanks [@arboleya](https://github.com/arboleya)! - Adjusting export fields for all packages

- Updated dependencies [[`f4e1028a`](https://github.com/FuelLabs/fuels-ts/commit/f4e1028acd5a583d12662dd07ca0d17084a35be2)]:
- @fuel-ts/interfaces@0.35.0
- @fuel-ts/keystore@0.35.0
- @fuel-ts/versions@0.35.0

## 0.34.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/address/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fuel-ts/address",
"version": "0.34.1",
"version": "0.35.0",
"description": "Utilities for encoding and decoding addresses",
"author": "Fuel Labs <[email protected]> (https://fuel.network/)",
"typedoc": {
Expand Down
Loading

0 comments on commit f6948ff

Please sign in to comment.