Plugins for Sui TypeScript SDK
The Move Registry (MVR, pronounced "mover") Sui TypeScript SDK plugin offers builders a seamless experience when constructing programmable transaction blocks (PTBs) using MVR names.
The plugin resolves MVR names to their respective addresses before constructing the PTB, caching the results during each runtime.
This also applies to type names, especially across package upgrades.
Recommended usage
The MVR plugin uses a runtime API to resolve named packages and types. While this is beneficial to the user experience, it naturally comes with considerations around performance, availability, and security.
For this reason, consider using the @mysten/mvr-static
plugin, which statically resolves all the package addresses and types during the build. The plugin caches your MVR references
and exports them to a resolution file.
This approach offers a couple of benefits:
- Enhanced user experience of leveraging MVR in your PTBs for names and types, for both Mainnet and Testnet.
- Performance (no extra calls to the MVR endpoint) and security of statically resolving MVR references at build time.
Check the NPM page for the @mysten/mvr-static
plugin (opens in a new tab) to learn more.
How to use
The plugin is functional starting from @mysten/sui
v1.25.0
The MVR plugin is exported directly from the @mysten/sui
package. To enable the plugin, register it either globally or per PTB in your dApp.
Endpoints
Mysten Labs provides public good endpoints compatible with the MVR plugin.
Mainnet: https://mainnet.mvr.mystenlabs.com
Testnet: https://testnet.mvr.mystenlabs.com
Register the plugin
Depending on the architecture of your dApp, you can register the plugin either globally or per PTB.
/** Register the MVR plugin globally */
import { namedPackagesPlugin, Transaction } from "@mysten/sui/transactions";
const plugin = namedPackagesPlugin({ url: '<endpoint based on network>' });
/** Register the MVR plugin globally (once) for our PTB construction */
Transaction.registerGlobalSerializationPlugin('namedPackagesPlugin', plugin);
/** Register the MVR plugin per PTB */
const mainnetPlugin = namedPackagesPlugin({ url: 'https://mainnet.mvr.mystenlabs.com' });
const testnetPlugin = namedPackagesPlugin({ url: 'https://testnet.mvr.mystenlabs.com' });
function createTransaction(network: 'mainnet' | 'testnet') {
const transaction = new Transaction();
transaction.addSerializationPlugin(network === 'mainnet' ? mainnetPlugin : testnetPlugin);
// continue with your transaction.
}
Defining overrides
If you want to use the plugin locally (for CI), or you want to cache results yourself (without the @mysten/mvr-static
generator),
you can define overrides for the package addresses and types.
const overrides = {
packages: {
'@suifrens/accessories': '0xe177697e191327901637f8d2c5ffbbde8b1aaac27ec1024c4b62d1ebd1cd7430',
},
types: {
'@suifrens/core::suifren::SuiFren': '0x80d7de9c4a56194087e0ba0bf59492aa8e6a5ee881606226930827085ddf2332::suifren::SuiFren',
'@suifrens/core::bullshark::Bullshark': '0x8894fa02fc6f36cbc485ae9145d05f247a78e220814fb8419ab261bd81f08f32::bullshark::Bullshark',
}
}
const plugin = namedPackagesPlugin({ url: '<endpoint based on network>', overrides });
Before / after example
The examples in the tabs are simplified for clarity. Actual addresses or names might differ.
Example of a PTB before MVR:
const transaction = new Transaction();
// testnet
// Notice how the suifren type has a V1 outer package id, and a V2 inner type package id,
// even if they are part of the same package upgrades.
transaction.moveCall({
target: `0xe177697e191327901637f8d2c5ffbbde8b1aaac27ec1024c4b62d1ebd1cd7430::accessories::equip`,
arguments: [..],
typeArguments: [
`0x80d7de9c4a56194087e0ba0bf59492aa8e6a5ee881606226930827085ddf2332::suifren::SuiFren<0x297d8afb6ede450529d347cf9254caeea2b685c8baef67b084122291ebaefb38::bullshark::Bullshark>`
]
});
// mainnet
transaction.moveCall({
target: `0x54800ebb4606fd0c03b4554976264373b3374eeb3fd63e7ff69f31cac786ba8c::accessories::equip`,
arguments: [..],
typeArguments: [
`0xee496a0cc04d06a345982ba6697c90c619020de9e274408c7819f787ff66e1a1::suifren::SuiFren<0x8894fa02fc6f36cbc485ae9145d05f247a78e220814fb8419ab261bd81f08f32::bullshark::Bullshark>`
]
});