@typemove/aptos v1.8.3
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 fortarget-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:
You can write code as follows:
import { defaultMoveCoder } from '@typemove/aptos'
import { stable_pool } from "./types/0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af";
const pool = await defaultMoveCoder().decodeType(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:
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.
8 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago