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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@mysten/codegen

v0.5.13

Published

typescript codegen for sui move

Readme

Sui typescript codegen

⚠️ Warning: This package is currently in development and may have breaking changes.

Setup

To use this package you will need to install it from npm:

pnpm install @mysten/codegen

Then create a sui-codegen.config.ts to define what packages you want to generate code for:

import type { SuiCodegenConfig } from './src/config.js';

const config: SuiCodegenConfig = {
	output: './src/generated',
	generateSummaries: true,
	prune: true,
	packages: [
		{
			package: '@your-scope/your-package',
			path: './move/your-package',
		},
	],
};

export default config;

The package field should be the MVR name for your move package. If you have not registered your package on MVR yet, you can use the @local-pkg scope, and set up an override in your SuiClient to resolve it to the correct address.

Generating code

To generate code, you will first need to create package_summaries for your package. You can do this by running the following command in the root of you move package:

sui move summary

this will create a new package_summaries directory (which can be added to .gitignore) for the codegen tool to analyze when generating code for your package.

If you are having trouble with this command, ensure you are using the latest version of the sui cli (version 1.51.1 or later).

Now that you have the package_summaries you can generate you typescript code, by running

pnpm sui-ts-codegen generate

or by adding something the following script to your package.json and running pnpm codegen

{
	"scripts": {
		"codegen": "sui-ts-codegen generate"
	}
}

Setting up SuiClient

If your package is registered on MVR, the generated code should work without additional configuration. If you are using a @local-pkg name, you will need to configure your SuiClient to resolver the package name correctly:

const client = new SuiClient({
	network: 'testnet',
	url: testnetRpcUrl,
	mvr: {
		overrides: {
			packages: {
				'@local-pkg/your-package': YOUR_PACKAGE_ID,
			},
		},
	},
});

If you are using dapp-kit, you may need to set up your network config and SuiClientProvider:

const { networkConfig, useNetworkVariable, useNetworkVariables } = createNetworkConfig({
	testnet: {
		url: getFullnodeUrl('testnet'),
		variables: {
			yourPackageId: YOUR_TESTNET_PACKAGE_ID,
		},
	},
});
<SuiClientProvider
	networks={networkConfig}
	defaultNetwork="testnet"
	createClient={(network, config) => {
		return new SuiClient({
			network,
			url: config.url,
			mvr: {
				overrides: {
					packages: {
						'@local-pkg/your-package': config.variables.yourPackageId,
					},
				},
			},
		});
	}}
>
	<App />
</SuiClientProvider>

Calling Move Functions

The generated code provides type-safe functions for calling Move functions. Here's how to use them:

Creating Objects

To create new objects from your Move package, use the generated create function:

This example assumes a simple counter package based on the create-dapp template:

import { Transaction } from '@mysten/sui/transactions';
import * as counter from './generated/counter/counter';

async function createCounter() {
	// create a new Transaction
	const tx = new Transaction();
	// Add a create call
	tx.add(counter.create());

	const { digest } = suiClient.signAndExecuteTransaction({
		transaction: tx,
		signer: keypair,
	});

	return digest;
}

async function incrementCount(id: string) {
	const tx = tx.add(
		counter.increment({
			// Arguments can be passed in by name as an object, or as an array of values
			arguments: {
				// Argument values can be js primitives, or use methods like tx.pure or tx.object, or results of other move calls
				counter: id,
			},
		}),
	);

	const { digest } = suiClient.signAndExecuteTransaction({
		transaction: tx,
		signer: keypair,
	});

	return digest;
}

Parsing BCS Types

The generated code also provides BCS definitions for your Move types:

First, you will need to load the bcs data for your object, then parse it with your generated type:

import * as counter from './generated/counter/counter';

async await function readCounter(id: string) {
	const data = suiClient.getObject({
		id,
		options: {
			// request the bcs data when loading your object
			showBcs: true,
		}
	})

	if (data.data.bcs?.dataType !== 'moveObject') {
	  throw new Error('Expected a move object')
	}

	return counter.Counter.fromBase64(data.data.bcs.bcsBytes)
}