1.8.3 • Published 6 months ago

@typemove/sui v1.8.3

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

TypeMove

Generate TypeScript bindings for Sui contracts.

Features

  • Code generation for SUI smart contract based on ABI
  • Typesafe encode/decoding, object filtering, transaction building, etc
  • Automatically manage depended modules
  • BCS schema (WIP)

Usage

Install package

yarn add @typemove/sui

or

pnpm add @typemove/sui

Code Generation

yarn typemove-sui [--target-dir] [--network] [--abi-dir] <location>
  • location: Directory of ABI json files or address of account to generate types for
  • target-dir: Directory to output generated files (default: "./types")
  • network: Network to use, could be either "mainnet", "testnet" or any node URL (default: "mainnet")
  • abi-dir: Directory to store downloaded ABI. Only useful if is address (default: "./abis")

Use yarn typemove-sui --help to see detail description.

A few examples:

  • generate types for an address on mainnet:
    yarn typemove-sui --target-dir=./src/types --abi-dir=./src/abis 0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5 
  • generate types for local ABI files stored in ./src/abis:
    yarn typemove-sui --target-dir=./src/types ./src/abis
  • generate types using local node:
    yarn typemove-sui --network="http://localhost:8080" 0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af

Decode Object

import { defaultMoveCoder } from '@typemove/sui'
import { single_collateral } from './types/testnet/0xebaa2ad3eacc230f309cd933958cc52684df0a41ae7ac214d186b80f830867d2.js'

const res = await defaultMoveCoder().decodeType(
  data,
  single_collateral.Info.type()
)
export interface Info {
  index: string;
  creator: string;
  createTsMs: string;
  round: string;
  deliveryInfo?: DeliveryInfo;
}
export interface DeliveryInfo {
  round: string;
  price: string;
  size: string;
  premium: string;
  tsMs: string;
}

let deliveryInfo: DeliveryInfo | undefined =
    // @ts-ignore
    data.content.fields.info.fields.delivery_info
        ? {
          // @ts-ignore
          round: data.content.fields.info.fields.delivery_info.fields.round,
          // @ts-ignore
          price: data.content.fields.info.fields.delivery_info.fields.price,
          // @ts-ignore
          size: data.content.fields.info.fields.delivery_info.fields.size,
          // @ts-ignore
          premium: data.content.fields.info.fields.delivery_info.fields.premium,
          // @ts-ignore
          tsMs: data.content.fields.info.fields.delivery_info.fields.ts_ms,
        }
        : undefined;
let info: Info = {
  // @ts-ignore
  index: data.content.fields.info.fields.index,
  // @ts-ignore
  creator: data.content.fields.info.fields.creator,
  // @ts-ignore
  createTsMs: data.content.fields.info.fields.create_ts_ms,
  // @ts-ignore
  round: data.content.fields.info.fields.round,
  deliveryInfo,
};

Decode dynamic fields

Get objects with specified type from a list of dynamic objects, and access field with fully typed object

const decodedObjects = await coder.getDynamicFields(
    objects,
    BUILTIN_TYPES.U64_TYPE,
    single_collateral.PortfolioVault.type()
)
console.log(decodedObjects[0].value.info.delivery_info?.price)

IDE could infer result type correctly. dynamic_fields.png

View Function

With type move, you could, call view functions and get decoded result very easily, e.g.

import { _0x2 } from '@typemove/sui/builtin'

res = (await _0x2.math.view.min(client, [20n, 4n]))

console.log(res?.results_decoded[0])

Typemove's generated view function stubs wraps the devInspectTransactionBlock API and decode the result, it adds an fully typed results_decoded field to the result object. e.g. the above min function generated has type annotation as below:

module math {
  export async function min(
      client: SuiClient,
      args: [bigint | TransactionArgument, bigint | TransactionArgument],
  ): Promise<TypedDevInspectResults<[bigint]>> {
  ...
  }
}

Building transaction

Similar to original transaction building process, but you could use generated builder function to replace the txb.moveCall.

import { clob_v2 } from './types/testnet/0xdee9.js'

const client = new SuiClient({ url: getFullnodeUrl('testnet') })
const tx = new TransactionBlock()
clob_v2.builder.createAccount(tx, ["0xd9e6dc1e7f0790c18acf96b629f0a236d56de2f96537d921197bcb0e071b12bd"])
    ... more tx build 
client.signAndExecuteTransactionBlock({transactionBlock: tx, signer: keypair})

Checkout our tests for more examples.

1.8.3-rc.1

6 months ago

1.8.3

6 months ago

1.8.2-rc.2

7 months ago

1.8.2-rc.1

7 months ago

1.8.2

7 months ago

1.8.1

7 months ago

1.8.1-rc.1

7 months ago

1.8.1-rc.2

7 months ago

1.8.0

7 months ago

1.8.0-rc.1

7 months ago

1.7.1-rc.1

8 months ago

1.7.0-rc.1

8 months ago

1.7.1

8 months ago

1.7.0

8 months ago

1.6.10-rc.1

8 months ago

1.6.9-rc.1

8 months ago

1.6.9

8 months ago

1.6.12-rc.2

8 months ago

1.6.12-rc.1

8 months ago

1.6.11

8 months ago

1.6.10

8 months ago

1.6.12

8 months ago

1.6.11-rc.1

8 months ago

1.6.7-rc.3

8 months ago

1.6.7-rc.2

8 months ago

1.6.7-rc.4

8 months ago

1.6.7-rc.1

8 months ago

1.6.8

8 months ago

1.6.7

8 months ago

1.6.8-rc.1

8 months ago

1.6.8-rc.2

8 months ago

1.6.6-rc.1

9 months ago

1.6.6-rc.2

9 months ago

1.6.6

9 months ago

1.6.5

9 months ago

1.6.5-rc.1

9 months ago

1.6.4

9 months ago

1.6.4-rc.1

9 months ago

1.6.3

11 months ago

1.6.3-rc.1

11 months ago

1.6.2

12 months ago

1.6.2-rc.3

12 months ago

1.6.1

1 year ago

1.6.2-rc.2

1 year ago

1.6.2-rc.1

1 year ago

1.6.1-rc.2

1 year ago

1.6.1-rc.1

1 year ago

1.6.0

1 year ago

1.6.0-rc.3

1 year ago

1.6.0-rc.2

1 year ago

1.6.0-rc.1

1 year ago

1.5.8-rc.1

1 year ago

1.5.7-rc.3

1 year ago

1.5.7-rc.1

1 year ago

1.5.7-rc.2

1 year ago

1.5.7

1 year ago

1.5.6-rc.2

1 year ago

1.5.6

1 year ago

1.5.6-rc.1

1 year ago

1.5.5

1 year ago

1.5.5-rc.1

1 year ago

1.5.4

1 year ago

1.5.4-rc.1

1 year ago

1.5.3

1 year ago

1.5.3-rc.3

1 year ago

1.5.3-rc.2

1 year ago

1.5.2-rc.2

1 year ago

1.5.2-rc.3

1 year ago

1.5.2

1 year ago

1.5.2-rc.4

1 year ago

1.5.3-rc.1

1 year ago

1.5.2-rc.1

1 year ago

1.5.1-rc.1

1 year ago

1.5.0-rc.1

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.1-rc.1

1 year ago

1.4.0

1 year ago

1.4.0-rc.1

1 year ago

1.3.5

1 year ago

1.3.5-rc.1

1 year ago

1.3.4-rc.1

1 year ago

1.3.4

1 year ago

1.3.3

1 year ago

1.3.3-rc.1

1 year ago

1.3.2

2 years ago

1.3.2-rc.1

2 years ago

1.3.1-rc.1

2 years ago

1.3.0-rc.2

2 years ago

1.3.0-rc.1

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.9

2 years ago

1.2.9-rc.1

2 years ago

1.2.8

2 years ago

1.2.8-rc.1

2 years ago

1.2.7

2 years ago

1.2.7-rc.2

2 years ago

1.2.7-rc.1

2 years ago

1.2.6

2 years ago

1.2.6-rc.5

2 years ago

1.2.6-rc.4

2 years ago

1.2.6-rc.3

2 years ago

1.2.6-rc.2

2 years ago

1.2.6-rc.1

2 years ago

1.2.5

2 years ago

1.2.5-rc.1

2 years ago

1.2.4-rc4

2 years ago

1.2.4-rc3

2 years ago

1.2.4-rc2

2 years ago

1.2.4

2 years ago

1.2.4-rc.1

2 years ago

1.2.3

2 years ago

1.2.3-rc.2

2 years ago

1.2.3-rc.1

2 years ago

1.2.2

2 years ago

1.2.2-rc.1

2 years ago

1.2.1

2 years ago

1.2.1-rc.1

2 years ago

1.2.0

2 years ago

1.2.0-rc.4

2 years ago

1.2.0-rc.3

2 years ago

1.2.0-rc.2

2 years ago

1.2.0-rc.1

2 years ago

1.1.0

2 years ago

1.1.0-rc.1

2 years ago

1.0.2-rc.2

2 years ago

1.0.2-rc.1

2 years ago

1.0.1

2 years ago

1.0.1-rc.1

2 years ago

1.0.0

2 years ago

1.0.0-rc.31

2 years ago

1.0.0-rc.30

2 years ago

1.0.0-rc.29

2 years ago

1.0.0-rc.28

2 years ago

1.0.0-rc.27

2 years ago

1.0.0-rc.26

2 years ago

1.0.0-rc.25

2 years ago

1.0.0-rc.24

2 years ago

1.0.0-rc.23

2 years ago

1.0.0-rc.22

2 years ago

1.0.0-rc.21

2 years ago

1.0.0-rc.20

2 years ago

1.0.0-rc.19

2 years ago

1.0.0-rc.18

2 years ago

1.0.0-rc.17

2 years ago

1.0.0-rc.16

2 years ago

1.0.0-rc.15

2 years ago

1.0.0-rc.14

2 years ago

1.0.0-rc.13

2 years ago

1.0.0-rc.12

2 years ago

1.0.0-rc.11

2 years ago

1.0.0-rc.10

2 years ago

1.0.0-rc.9

2 years ago

1.0.0-rc.8

2 years ago

1.0.0-rc.7

2 years ago

1.0.0-rc.6

2 years ago

1.0.0-rc.5

2 years ago

1.0.0-rc.4

2 years ago