Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fuel-ts/abi-typegen

Package Overview
Dependencies
Maintainers
0
Versions
2928
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fuel-ts/abi-typegen

Generates Typescript definitions from Sway ABI Json files

  • 0.97.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
16K
increased by29.06%
Maintainers
0
Weekly downloads
 
Created
Source

@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
u640xFFFFFFFFFFFFFFFF BigNumberishBN
stranythingstringstring
booltruebooleanboolean
b2560x000...stringstring
b512fuel1a7r...stringstring
tuples(MyType, MyType)[MyType, MyType][MyType, 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.

FAQs

Package last updated on 13 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc