0.77.0 • Published 2 months ago

@fuel-ts/abi-typegen v0.77.0

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
2 months ago

@fuel-ts/abi-typegen

Generate TypeScript bindings for Sway smart contracts.

See the full ABI-spec here.

Table of contents

Documentation

See Fuel-ts Documentation

Installation

yarn add @fuel-ts/abi-typegen
# or
npm add @fuel-ts/abi-typegen

Help

$ fuels-typegen -h
Usage: fuels-typegen -i ../out/*-abi.json -o ./generated/

Options:
  -V, --version            output the version number
  -i, --input <path|glob>  input path/global to your abi json files
  -o, --output <dir>       directory path for generated files
  -s, --silent             omit output messages
  -h, --help               display help for command

Generating types

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

import { 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' ]

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

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

Full SDK Installation

Alternatively, we recommend you install the complete SDK using the umbrella package:

yarn add fuels
# or
npm add fuels

Note that in this example we will interact with the fuels bin directly.

We just need to call it with the typegen command, and the rest feels the same.

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

Type's Conversion Table

The table below describes how Sway types are converted from/to Typescript.

SwayExampleTS:inputTS:output
u8255BigNumberishnumber
u1665535BigNumberishnumber
u324294967295BigNumberishnumber
u640xFFFFFFFFFFFFFFFFBigNumberishBN
stranythingstringstring
booltruebooleanboolean
b2560x000...stringstring
b512fuel1a7r...stringstring
tuples(MyType, MyType)MyType, MyTypeMyType, MyType
enumsenum MyEnum { y: (), n: () }MyEnum = Enum<{ y: [], n: [] }>MyEnum = Enum<{ y: [], n: [] }>
structsMyStruct { a: u8, b: u16 }MyStructMyStruct
vectorsVec<MyType>MyType[]MyType[]
optionsOption<MyType>Option<MyType>Option<MyType>
raw untyped ptr123BigNumberishnumber

For more info on Sway types, click here

Contributing

In order to contribute to @fuel-ts/abi-typegen, please see the main fuels-ts monorepo.

Changelog

The @fuel-ts/abi-typegen changelog can be found at CHANGELOG.

License

The primary license for @fuel-ts/abi-typegen is Apache 2.0, see LICENSE.

0.77.0

2 months ago

0.76.0

2 months ago

0.75.0

2 months ago

0.74.0

3 months ago

0.73.0

3 months ago

0.72.0

3 months ago

0.71.1

4 months ago

0.70.1

4 months ago

0.71.0

4 months ago

0.69.1

5 months ago

0.68.0

5 months ago

0.69.0

5 months ago

0.55.0

8 months ago

0.67.0

6 months ago

0.56.1

8 months ago

0.56.0

8 months ago

0.64.1

7 months ago

0.64.0

7 months ago

0.53.0

9 months ago

0.65.0

7 months ago

0.54.1

8 months ago

0.54.0

8 months ago

0.66.1

6 months ago

0.66.0

6 months ago

0.59.0

8 months ago

0.48.2

10 months ago

0.48.0

10 months ago

0.48.1

10 months ago

0.49.1

9 months ago

0.49.0

10 months ago

0.57.0

8 months ago

0.46.0

10 months ago

0.58.0

8 months ago

0.47.0

10 months ago

0.62.0

7 months ago

0.51.0

9 months ago

0.63.0

7 months ago

0.52.0

9 months ago

0.60.0

8 months ago

0.61.0

7 months ago

0.50.0

9 months ago

0.44.2

11 months ago

0.45.0

11 months ago

0.43.0

12 months ago

0.44.0

11 months ago

0.44.1

11 months ago

0.41.0

1 year ago

0.42.0

12 months ago

0.39.1

1 year ago

0.39.0

1 year ago

0.43.1

12 months ago

0.40.0

1 year ago

0.36.0

1 year ago

0.37.1

1 year ago

0.37.0

1 year ago

0.38.1

1 year ago

0.38.0

1 year ago

0.34.1

1 year ago

0.34.0

1 year ago

0.35.0

1 year ago

0.33.0

1 year ago

0.32.0

1 year ago

0.31.0

1 year ago

0.30.0

1 year ago

0.29.1

1 year ago

0.29.0

1 year ago

0.28.1

1 year ago

0.28.0

1 year ago

0.27.0

1 year ago

0.26.0

1 year ago

0.25.1

1 year ago

0.25.0

1 year ago