Package Exports
- @layerzerolabs/lz-movevm-sdk-v2
- @layerzerolabs/lz-movevm-sdk-v2/package.json
Readme
MoveVM SDK
The MoveVM SDK is a comprehensive toolkit designed to interact with the Move-based blockchain. It provides a set of utilities and modules to facilitate the development and integration of applications with the MoveVM.
Features
- Price Feed Management: Interact with price feeds, set and get prices.
- ULN Configuration: Manage ULN configurations for sending and receiving messages.
- Executor Configuration: Set and get executor configurations.
- Worker Management: Manage worker configurations and price feeds.
- View Functions: Execute view functions to retrieve data from the blockchain.
Installation
To install the MoveVM SDK, you can use npm or yarn:
npm install @layerzerolabs/movevm-sdk
or
yarn add @layerzerolabs/movevm-sdk
Usage
Normally you don't need to use this package directly, you can use @layerzerolabs/lz-aptos-sdk-v2 or @layerzerolabs/lz-initia-sdk-v2 to interact with Aptos or Initia blockchain, both of them have implemented the MoveSdkImpl interface.
However, if you need to interact with other blockchains but neither Aptos nor Initia, you need to create your own SDK first, add @layerzerolabs/movevm-sdk as a dependency, and implements the MoveSdkImpl interface.
Here's an example from @layerzerolabs/lz-initia-sdk-v2
Initialization
import { AccountsOption, LayerZeroModulesSdk, MoveSdkImpl } from '@layerzerolabs/lz-movevm-sdk-v2'
import { MnemonicKey } from '@initia/initia.js'
import {
EntryFunctionArgumentTypes,
GasOptions,
MnemonicAndPath,
MoveFunction,
MoveStructId,
MoveValue,
PrivateKey,
TableItemRequest,
TransactionResponse
} from '@layerzerolabs/move-definitions'
export class SDK implements MoveSdkImpl<MnemonicKey> {
LayerzeroModule: LayerZeroModulesSdk<MnemonicKey>
accounts: AccountsOption
constructor() {
this.accounts = {
price_feed: '0x1',
uln_message_lib: '0x2',
worker_common: '0x3',
layerzero_views: '0x4',
},
this.LayerzeroModule = new LayerZeroModulesSdk(this)
async viewFunction(args: {
functionName: MoveFunction
functionArgs: EntryFunctionArgumentTypes[]
functionArgTypes?: string[]
typeArgs?: string[]
}): Promise<MoveValue[]> {
// your implementation
}
async sendAndConfirmTransaction(
sender: MnemonicKey | PrivateKey | MnemonicAndPath,
func: MoveFunction,
args: EntryFunctionArgumentTypes[],
multisig?: string | Uint8Array,
argTypes?: string[],
gasOptions?: GasOptions
): Promise<TransactionResponse> {
// your implementation
}
async getAccountResource<T extends NonNullable<unknown> = any>(args: {
accountAddress: string | Uint8Array
resourceType: MoveStructId
options?: unknown
}): Promise<T> {
// your implementation
}
async getTableItem<T>(args: { handle: string; data: TableItemRequest; options?: unknown }): Promise<T> {
// your implementation
}
normalizeAddress(address: string): string {
return address
}
normalizeSigner(signer: MnemonicKey | PrivateKey | MnemonicAndPath): MnemonicKey {
// your implementation
}
accountToAddress(account: MnemonicKey): string {
// your implementation
}
supportsCoin(): boolean {
return false
}
}
Interact with SDK method
After you create a SDK instance, you can simply invoke any SDK methods.
Here's an example. (Suppose you need to call the isSetZro method in Endpoint SDK)
const SDK = new SDK();
const result = await SDK.LayerzeroModule.Endpoint.isSetZro();
// your remaining implementation