Configuration | JS API Reference
The JavaScript SDK can be configured with a variety of options. These options can be set globally, or on a per-instance basis.
Initialization
Initializing the Mirror World SDK only requires 2 properties in the
MirrorWorld
constructor object:
apiKey
- Project's API Key acquired from the developer dashboardchainConfig
- Chain configuration object for the chain you would like to use. (The chain configuration can also be modified after initialization)
Multichain Configuration
The Mirror World JS SDK exports configuration factories for following multiple chains:
Solana
- Solana chain configurationEthereum
- Ethereum chain configurationBNBChain
- BNB Chain configurationPolygon
- Polygon chain configurationSUIChain
- SUI Chain 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 "@mirrorworld/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.
Chain / Network Configurations
The table below shows the network names configuration parameters accepted by the corresponding chain.
Chain | Mainnet name | Testnet name |
---|---|---|
Solana | mainnet-beta | devnet |
Polygon | mumbai-mainnet | mumbai-testnet |
BNBChain | bnb-mainnet | bnb-testnet |
Ethereum | mainnet | goerli |
SUIChain | mainnet | testnet |
For example, below is an example of how to initialize the SDK on Polygon Testnet and mint an NFT
import { MirrorWorld, Polygon } from "@mirrorworld/web3.js"const mirrorworld = new MirrorWorld({ apiKey: "YOUR_API_KEY", chainConfig: Polygon("mumbai-testnet"),})await mirrorworld.Polygon.Asset.mintNFT(/** ... */)
Configuration Options
export interface MirrorWorldOptions { /** * API Key used to authenticate your API requests to Mirror World. */ apiKey: string /** * Chain configuration for Mirror World SDK */ chainConfig: ChainConfig<ChainTypes> /** * Authentication options */ auth?: { // Authentication token authToken?: string // Developer Secret Access Key. Used when interacting with the SDK on the server-side. secretAccessKey?: string } /** * When passed, the Mirror World SDK will automatically log in * the user using their `refresh_token`. This expects the * refresh token returned with the user when logging in. */ autoLoginCredentials?: string /** * Wallet UI configuration options */ walletUIConfig?: { /** * When the `uxMode` is set to `popup`, it uses a new window when interacting with the Wallet UI. * When the `uxMode` is set to `embedded`, it uses an iframe when interacting with the Wallet UI. */ uxMode: "popup" | "embedded" }}
Usage with Node.js
When using the Mirror World Smart SDK with Node.js, you may need to authenticate the SDK with your API Key and Secret Access Key.
Providing this token will bypass approval for developer wallets. Learn more about the Secret Access Key.
import { MirrorWorld, Polygon } from "@mirrorworld/web3.js"const mirrorworld = new MirrorWorld({ apiKey: "YOUR_API_KEY", chainConfig: Polygon("mumbai-testnet"), auth: { secretAccessKey: "YOUR_SECRET_ACCESS_KEY", },})
What's next?
After the initialization is done, if you want to call the SDK's interface, you need to first have the user log in to obtain a token.
import { MirrorWorld, Solana } from '@mirrorworld/web3.js';const mirrorworld = ref<MirrorWorld>( new MirrorWorld({ apiKey: 'YOUR_SECRET_API_KEY', chainConfig: Solana('mainnet-beta'), }));// Login user with Social Authenticationasync function login() { await mirrorworld.value.login();}
Advanced Concepts
Dynamic Chain Configuration
When building multichain applciations with the Mirror World SDK, you may
encounter some scenarios where you may want to switch from one chain to another.
To perform this kind of switch, you can reassign the chainConfig
property on
the MirrorWorld
instance:
// Reassigns chain config to Solana devnetmirrorworld.chainConfig = Solana("devnet")console.log(mirrorworld.chainConfig) // { chain: "solana", network: "devnet" }// Reassigns chain config to Ethereum mainnetmirrorworld.chainConfig = Ethereum("mainnet")console.log(mirrorworld.chainConfig) // { chain: "ethereum", network: "mainnet" }// Reassigns chain config to BNB Chain mainnetmirrorworld.chainConfig = BNBChain("bnb-mainnet")console.log(mirrorworld.chainConfig) // { chain: "bnb", network: "bnb-mainnet" }
Edit this page on GitHub