1.5.7 • Published 2 days ago

@typemove/aptos v1.5.7

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

TypeMove

Generate TypeScript bindings for Aptos contracts.

Features

  • Code generation for Aptos smart contract based on ABI
  • Typesafe encode/decoding, object filtering, transaction building, etc
  • Automatically manage depended modules

Usage

Install package

yarn add @typemove/aptos

or

pnpm add @typemove/aptos

Code Generation

yarn typemove-aptos [--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-aptos --help to see detail description.

A few examples:

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

Decode object

Generated type will be like this: img.png

You can write code as follows:

import { defaultMoveCoder } from '@typemove/aptos'
import { stable_pool } from "./types/0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af";

const pool = await defaultMoveCoder().decodedType(stable_pool.StablePool.type(), object)

Checkout our tests for more examples。

View function

Sample code is as follows:

const aptosClient = new AptosClient("https://fullnode.mainnet.aptoslabs.com")
const [lpName] = await stable_pool.view.lpNameById(client, { arguments: [3n] })
const [poolBalances, weights, supply] = await stable_pool.view.poolInfo(client, { arguments: [lpName] })

IDE will show you the detail type of the function:

img.png

Build transaction

Similar to view function, but use entry instead of view:

const aptosClient = new AptosClient("https://fullnode.mainnet.aptoslabs.com")
const account = new AptosAccount(...)
const res = await _0x1.coin.entry.transfer(client, account, {
  type_arguments: ['0x1::aptos_coin::AptosCoin'],
  arguments: ['0x1', 1n],
})

Checkout our tests for more examples.

Resource client

We provide a resource client to help you retrieve resources:

const poolType = amm.Pool.type()
const allPoolResources = await accountResourceClient.matchAll(ACCOUNT_ADDRESS, poolType)

or if you want to partial match one of the type parameters:

const poolTypeWithAptos = amm.Pool.type(aptos_coin.AptosCoin.type(), ANY_TYPE)
const aptosPoolResources = await accountResourceClient.matchAll(ACCOUNT_ADDRESS, poolTypeWithAptos)

Checkout our tests for more examples.

1.5.7-rc.3

2 days ago

1.5.7-rc.1

2 days ago

1.5.7-rc.2

2 days ago

1.5.7

2 days ago

1.5.6-rc.2

17 days ago

1.5.6

17 days ago

1.5.6-rc.1

2 months ago

1.5.5

2 months ago

1.5.5-rc.1

2 months ago

1.5.4-rc.1

3 months ago

1.5.4

3 months ago

1.5.3

3 months ago

1.5.3-rc.3

3 months ago

1.5.3-rc.2

3 months ago

1.5.2-rc.2

3 months ago

1.5.2-rc.3

3 months ago

1.5.2

3 months ago

1.5.2-rc.4

3 months ago

1.5.3-rc.1

3 months ago

1.5.2-rc.1

3 months ago

1.5.1-rc.1

3 months ago

1.5.0-rc.1

3 months ago

1.5.1

3 months ago

1.5.0

3 months ago

1.4.1-rc.1

3 months ago

1.4.0

4 months ago

1.4.0-rc.1

4 months ago

1.3.5

4 months ago

1.3.5-rc.1

4 months ago

1.3.4-rc.1

4 months ago

1.3.4

4 months ago

1.3.3

4 months ago

1.3.3-rc.1

4 months ago

1.3.2

4 months ago

1.3.2-rc.1

4 months ago

1.3.1-rc.1

5 months ago

1.3.0-rc.2

5 months ago

1.3.0-rc.1

5 months ago

1.3.1

5 months ago

1.3.0

5 months ago

1.2.9

5 months ago

1.2.9-rc.1

5 months ago

1.2.8

6 months ago

1.2.8-rc.1

6 months ago

1.2.7

6 months ago

1.2.7-rc.2

6 months ago

1.2.7-rc.1

6 months ago

1.2.6

6 months ago

1.2.6-rc.5

6 months ago

1.2.6-rc.4

6 months ago

1.2.6-rc.3

6 months ago

1.2.6-rc.2

6 months ago

1.2.6-rc.1

6 months ago

1.2.5

6 months ago

1.2.5-rc.1

6 months ago

1.2.4-rc4

6 months ago

1.2.4-rc3

6 months ago

1.2.4-rc2

6 months ago

1.2.4

6 months ago

1.2.4-rc.1

6 months ago

1.2.3

7 months ago

1.2.3-rc.2

7 months ago

1.2.3-rc.1

7 months ago

1.2.2

8 months ago

1.2.2-rc.1

8 months ago

1.2.1

8 months ago

1.2.1-rc.1

8 months ago

1.2.0

8 months ago

1.2.0-rc.4

8 months ago

1.2.0-rc.3

8 months ago

1.2.0-rc.2

8 months ago

1.2.0-rc.1

8 months ago

1.1.0

8 months ago

1.1.0-rc.1

8 months ago

1.0.2-rc.2

8 months ago

1.0.2-rc.1

8 months ago

1.0.1

9 months ago

1.0.1-rc.1

9 months ago

1.0.0

9 months ago

1.0.0-rc.31

9 months ago

1.0.0-rc.30

9 months ago

1.0.0-rc.29

9 months ago

1.0.0-rc.28

9 months ago

1.0.0-rc.27

9 months ago

1.0.0-rc.26

9 months ago

1.0.0-rc.25

9 months ago

1.0.0-rc.24

9 months ago

1.0.0-rc.23

9 months ago

1.0.0-rc.22

9 months ago

1.0.0-rc.21

9 months ago

1.0.0-rc.20

9 months ago

1.0.0-rc.19

9 months ago

1.0.0-rc.18

10 months ago

1.0.0-rc.17

10 months ago

1.0.0-rc.16

10 months ago

1.0.0-rc.15

10 months ago

1.0.0-rc.14

10 months ago

1.0.0-rc.13

10 months ago