npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@typemove/aptos

v1.5.6

Published

<p align="center"> <img src="../../images/logo.png" width="300" alt="TypeChain"> </p>

Downloads

6,037

Readme

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.