Skip to main content
BETA
HomeIntegration BuilderAPI ReferenceGuides
View Mirror World on Github
Join the Discord server

Upgrading to v2 of the JS SDK

By Jonathan Bakebwa

In this guide, we'll go over the changes you need to make to upgrade to v2 of the JS SDK.

Breaking Changes

  • The env constructor property has been removed the constructor options in favour of the chainConfig property.
  • The clusterEnv, tokens, nfts and transaction accessors have been removed from the MirrorWorld class instance. You can now asynchronously fetch these resources directly from the corresponding chain methods.

Upgrade Steps

To install the latest version of the JS SDK, run the following command:


pnpm add @usemirrorworld/web3.js
# or with Yarn
yarn add @usemirrorworld/web3.js
# or with NPM
npm install @usemirrorworld/web3.js

Defining a chain configuration

The Mirror World JS SDK exports configuration factories for following multiple chains:

  • Solana - Solana chain configuration
  • Ethereum - Ethereum chain configuration
  • BNBChain - BNB Chain configuration
  • Polygon - Polygon chain configuration

Learn more about Mirror World's Multichain Support Matrix here

Below is an example of how to initialize the SDK with a Solana Configuration for the mainnet-beta network.


import { MirrorWorld, Solana } from "@usemirrorworld/web3.js"
const mirrorworld = new MirrorWorld({
apiKey: "YOUR_API_KEY",
chainConfig: Solana("mainnet-beta"),
})

After assigning this configuration, you can now invoke Solana methods with the SDK.

The table below shows the network names configuration parameters accepted by the corresponding chain.

ChainMainnet nameTestnet name
Solanamainnet-betadevnet
Polygonmumbai-mainnetmumbai-testnet
BNBChainbnb-mainnetbnb-testnet
Ethereummainnetgoerli

For example, below is an example of how to initialize the SDK on Polygon Testnet and mint an NFT


import { MirrorWorld, Solana } from "@usemirrorworld/web3.js"
const mirrorworld = new MirrorWorld({
apiKey: "YOUR_API_KEY",
chainConfig: Polygon("mumbai-testnet"),
})
await mirrorworld.Polygon.Asset.mintNFT(/** ... */)

To find the full initialization options for each chain, check out the Configuration options page.

Multichain Support

One of the most exciting new features of v2 of the Mirror World SDK is the multichain support. This means that you can now use the same SDK instance to interact with multiple chains. This is especially useful if you are building a dApp that supports multiple chains.

To use the multichain support, you need to initialize the SDK with a chainConfig property. This property accepts an object of chain configurations from the previous section.

Invoking chain-specific methods.

In order to invoke a specific method on a chain, you need to use the chain accessor, and service accessors to invoke the method.

For example, to invoke the mintNFT method on the Polygon mainnet chain, you would do the following:


import { MirrorWorld, Polygon } from "@usemirrorworld/web3.js"
const mirrorworld = new MirrorWorld({
apiKey: "YOUR_API_KEY",
chainConfig: Polygon("mumbai-mainnet"),
})
await mirrorworld.Polygon.Asset.mintNFT({
collection_address: "0xB11c14E2F322deC851795224A171Bcf03Dc8573D",
token_id: 4,
})

To find the full list of chain accessors and service accessors, check out the Full JavaScript API Reference page.

All done!

At this point, you should be all set to start using the Mirror World JS SDK v2.

If you have any questions, feel free to reach out to us on our Discord developer community

Happy Hacking!

Edit this page on GitHub

Copyright © Mirror World, Inc. 2023
On this page

Home

Integration

Guides

API Reference