0.96.1 • Published 9 months ago

@fuel-ts/abi-typegen v0.96.1

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

@fuel-ts/abi-typegen

Generate TypeScript bindings for Sway smart contracts.

See the full ABI-spec here.

Table of contents

Documentation

See Fuels-ts Documentation

Installation

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

Help

$ fuels-typegen -h

Generate Typescript from Sway ABI JSON files

Usage: fuels-typegen [options]

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
  -c, --contract               Generate types for Contracts [default]
  -s, --script                 Generate types for Scripts
  -p, --predicate              Generate types for Predicates
  -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

Programmatic API

import { ProgramTypeEnum, 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 programType = ProgramTypeEnum.CONTRACT;

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

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

Full SDK Installation

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

pnpm 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 ptr123BigNumberishBN

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.94.9

9 months ago

0.94.7

10 months ago

0.94.8

10 months ago

0.95.0

9 months ago

0.96.0

9 months ago

0.96.1

9 months ago

0.94.6

10 months ago

0.94.5

10 months ago

0.94.4

11 months ago

0.94.3

11 months ago

0.94.2

11 months ago

0.90.0

1 year ago

0.81.0

1 year ago

0.94.1

11 months ago

0.94.0

11 months ago

0.85.0

1 year ago

0.78.0

1 year ago

0.87.0

1 year ago

0.82.0

1 year ago

0.91.0

1 year ago

0.86.0

1 year ago

0.76.11

1 year ago

0.76.10

1 year ago

0.76.12

1 year ago

0.79.0

1 year ago

0.88.0

1 year ago

0.88.1

1 year ago

0.92.0

1 year ago

0.92.1

12 months ago

0.83.0

1 year ago

0.76.5

1 year ago

0.76.8

1 year ago

0.76.7

1 year ago

0.76.2

1 year ago

0.76.1

1 year ago

0.76.4

1 year ago

0.76.3

1 year ago

0.76.9

1 year ago

0.89.0

1 year ago

0.89.1

1 year ago

0.89.2

1 year ago

0.93.0

12 months ago

0.80.0

1 year ago

0.84.0

1 year ago

0.77.0

1 year ago

0.76.0

1 year ago

0.75.0

1 year ago

0.74.0

1 year ago

0.73.0

1 year ago

0.72.0

1 year ago

0.71.1

2 years ago

0.70.1

2 years ago

0.71.0

2 years ago

0.69.1

2 years ago

0.68.0

2 years ago

0.69.0

2 years ago

0.55.0

2 years ago

0.67.0

2 years ago

0.56.1

2 years ago

0.56.0

2 years ago

0.64.1

2 years ago

0.64.0

2 years ago

0.53.0

2 years ago

0.65.0

2 years ago

0.54.1

2 years ago

0.54.0

2 years ago

0.66.1

2 years ago

0.66.0

2 years ago

0.59.0

2 years ago

0.48.2

2 years ago

0.48.0

2 years ago

0.48.1

2 years ago

0.49.1

2 years ago

0.49.0

2 years ago

0.57.0

2 years ago

0.46.0

2 years ago

0.58.0

2 years ago

0.47.0

2 years ago

0.62.0

2 years ago

0.51.0

2 years ago

0.63.0

2 years ago

0.52.0

2 years ago

0.60.0

2 years ago

0.61.0

2 years ago

0.50.0

2 years ago

0.44.2

2 years ago

0.45.0

2 years ago

0.43.0

2 years ago

0.44.0

2 years ago

0.44.1

2 years ago

0.41.0

2 years ago

0.42.0

2 years ago

0.39.1

2 years ago

0.39.0

2 years ago

0.43.1

2 years ago

0.40.0

2 years ago

0.36.0

2 years ago

0.37.1

2 years ago

0.37.0

2 years ago

0.38.1

2 years ago

0.38.0

2 years ago

0.34.1

2 years ago

0.34.0

2 years ago

0.35.0

2 years ago

0.33.0

2 years ago

0.32.0

2 years ago

0.31.0

2 years ago

0.30.0

2 years ago

0.29.1

2 years ago

0.29.0

3 years ago

0.28.1

3 years ago

0.28.0

3 years ago

0.27.0

3 years ago

0.26.0

3 years ago

0.25.1

3 years ago

0.25.0

3 years ago