Skip to main content
BETA
View Zag.js on Github
Join the Discord server

JavaScript API Reference

Authentication Methods

All authentication methods on the JavaScript SDK

login

Authenticates a user using a customized user interface. It supports social authentication with Google, Twitter, Discord and Apple. This method opens a UI that authenticates the user.

import { MirrorWorld, ClusterEnvironment } from "@mirrorworld/web3.js" const mirrorworld = new MirrorWorld({ apiKey: "YOUR_SECRET_API_KEY", env: ClusterEnvironment.mainnet }) const { refreshToken } = await mirrorworld.login()

loginWithEmail

Logs in a user with email and password. This method is accessible in the browser and in Node.js.

import { MirrorWorld, ClusterEnvironment } from "@mirrorworld/web3.js" const mirrorworld = new MirrorWorld({ apiKey: "YOUR_SECRET_API_KEY", env: ClusterEnvironment.mainnet, }) const { refreshToken } = await mirrorworld.loginWithEmail({ email: "[email protected]", password: "super-secret-password" })

fetchUser

Fetches the current user's object.

const user = await mirrorworld.fetchUser() // Returns UserWithWallet object export interface UserWithWallet { id: number; eth_address: string; sol_address: string; email: string; email_verified: boolean; username: string; createdAt: string; updatedAt: string; wallet: { eth_address: string; sol_address: string; }; }

getTokens

Get's the current user's tokens

const tokens = await mirrorworld.getTokens() // Returns ISolanaToken array export interface ISolanaToken { ata: string; mint: string; amount: string; }

getTransactions

Get's the current user's transaction history

const tokens = await mirrorworld.getTransactions()

getNFTs

Fetches the current user's NFTs.

const nfts = await mirrorworld.getNFTs()

getNftDetails

Fetches an NFT's details by mint address

const mintAddress = "Ct1GvgpBzzhMtKb7nKc3U3kouPA3fHncAahPY1HthB9E" const nft = await mirrorworld.getNftDetails(mintAddress)

getNFTsOwnedByAddress

Fetches the NFTs owned by a specific address.

const walletAddress = "C64RkD2jnvrFF8mi9FUBwfhNHuuiPuRMzCLRSWcyJKUG" const nft = await mirrorworld.getNftDetails(walletAddress, { limit: 20, // page size offset: 0 // page number })

Wallet Methods

transferSPLToken

Transfer SPL token to a recipient

const recipientAddress = "C64RkD2jnvrFF8mi9FUBwfhNHuuiPuRMzCLRSWcyJKUG" const tokenMint = "5WCTV62V2X7iXdRdre73omXcF5agaYq3vj5kCXp6Mzdc" const tokenDecimals = 6 const amount = 200000 const transactionResult = await mirrorworld.transferSPLToken({ recipientAddress, amount, tokenMint, tokenDecimals, }) // Returns `ITransferSPLTokenResponse` export interface ITransferSPLTokenResponse { status: string; txSignature: string; }

transferSOL

Transfer SOL to wallet address

const recipientAddress = "C64RkD2jnvrFF8mi9FUBwfhNHuuiPuRMzCLRSWcyJKUG" const amount = 200000 // Amount * Decimals const transactionResult = await mirrorworld.transferSOL({ recipientAddress, amount, }) // Returns `ITransferSPLTokenResponse` export interface ITransferSPLTokenResponse { status: string; txSignature: string; }

Marketplace Methods

createVerifiedCollection

Create a new Verified Collection

const collection = await mirrorworld.createVerifiedCollection({ name: "COLLECTION_NAME", symbol: "COLLECTION_SYMBOL", metadataUri: "https://my-collection-metadata-uri/metadata.json" }) // Returns `IVerifiedCollection` export interface IVerifiedCollection { mint_address: string; url: string; update_authority: string; creator_address: string; name: string; symbol: string; collection?: null; signature: string; status: string; }

createVerifiedSubCollection

Create a new Verified Sub Collection. A subcollection is a collection that belongs to a main collection

const collection = await mirrorworld.createVerifiedSubCollection({ name: "COLLECTION_NAME", symbol: "COLLECTION_SYMBOL", metadataUri: "https://my-collection-metadata-uri/metadata.json", parentCollection: "FihfE3fXMWNTZ1piVxxdc1YnzaAw4cao6WGXz3C7PMu9" }) // Returns `IVerifiedCollection` export interface IVerifiedCollection { mint_address: string; url: string; update_authority: string; creator_address: string; name: string; symbol: string; collection?: null; signature: string; status: string; }

mintNFT

Mint NFT into collection

const nft = await mirrorworld.mintNFT({ name: `NFT_NAME`, symbol: `NFT_SYMBOL`, metadataUri: "https://my-collection-metadata-uri/metadata.json", collection: "FihfE3fXMWNTZ1piVxxdc1YnzaAw4cao6WGXz3C7PMu9" }) // Returns `ISolanaNFTMintResult` export interface ISolanaNFTMintResult { mint_address: string; url: string; update_authority: string; creator_address: string; name: string; symbol: string; collection: string; signature: string; status: string; }

listNFT

List NFT on Mirror World Marketplace

const listing = await mirrorworld.listNFT({ mintAddress: `Hc2My3GQCQTXTjV34Pi1pQGYUeckT1mEcMRiZZaH7Ydr`, price: 2, // Amount in SOL }) // Returns `INFTListing` export interface INFTListing { id: number; type: string; wallet_address: string; mint_address: string; price: string; seller_address: string; signature: string; status: string; updatedAt: string; createdAt: string; to_wallet_address?: null; }

buyNFT

Purchase NFT on Mirror World Marketplace

const listing = await mirrorworld.buyNFT({ mintAddress: `Hc2My3GQCQTXTjV34Pi1pQGYUeckT1mEcMRiZZaH7Ydr`, price: 2, // Amount in SOL }) // Returns `INFTListing` export interface INFTListing { id: number; type: string; wallet_address: string; mint_address: string; price: string; seller_address: string; signature: string; status: string; updatedAt: string; createdAt: string; to_wallet_address?: null; }

updateNFTListing

Update NFT Listing on Mirror World Marketplace

const listing = await mirrorworld.updateNFTListing({ mintAddress: `Hc2My3GQCQTXTjV34Pi1pQGYUeckT1mEcMRiZZaH7Ydr`, price: 2, // Amount in SOL }) // Returns `INFTListing` export interface INFTListing { id: number; type: string; wallet_address: string; mint_address: string; price: string; seller_address: string; signature: string; status: string; updatedAt: string; createdAt: string; to_wallet_address?: null; }

cancelNFTListing

Cancel listing NFT on Mirror World Marketplace

const listing = await mirrorworld.cancelNFTListing({ mintAddress: `Hc2My3GQCQTXTjV34Pi1pQGYUeckT1mEcMRiZZaH7Ydr`, price: 2, // Amount in SOL }) // Returns `INFTListing` export interface INFTListing { id: number; type: string; wallet_address: string; mint_address: string; price: string; seller_address: string; signature: string; status: string; updatedAt: string; createdAt: string; to_wallet_address?: null; }

transferNFT

Transfer NFT from holder's wallet to another address

const transactionResult = await mirrorworld.transferNFT({ mintAddress: `Hc2My3GQCQTXTjV34Pi1pQGYUeckT1mEcMRiZZaH7Ydr`, recipientAddress: `C64RkD2jnvrFF8mi9FUBwfhNHuuiPuRMzCLRSWcyJKUG`, }) // Returns `ITransactionResult` export interface ITransactionResult { id: number; type: string; wallet_address: string; mint_address: string; price: string; seller_address: string; signature: string; status: string; updatedAt: string; createdAt: string; to_wallet_address?: null; }

fetchNFTsByMintAddresses

Fetch NFTs By Mint Addresses. Returns a detailed payload of all NFTs whose mintAddresses are provided

const nftsQueryResult: SolanaNFTExtended[] = await mirrorworld.fetchNFTsByMintAddresses({ mintAddresses: [`Hc2My3GQCQTXTjV34Pi1pQGYUeckT1mEcMRiZZaH7Ydr`], limit: 20, // page size offset: 0 // page number }) // Returns `SolanaNFTExtended[]` export interface SolanaNFTExtended { name: string; sellerFeeBasisPoints: number; updateAuthorityAddress: string; description: string; image: string; externalUrl: string; creators: Creator[]; owner: Owner; attributes: MetadataAttributes[]; listings: SolanaNFTListing[]; }

fetchNFTsByCreatorAddresses

Fetch NFTs By Creator Addresses. Returns a detailed payload of all NFTs whose creatorAddresses are provided

const nftsQueryResult: SolanaNFTExtended[] = await mirrorworld.fetchNFTsByMintAddresses({ creatorAddresses: [`Hc2My3GQCQTXTjV34Pi1pQGYUeckT1mEcMRiZZaH7Ydr`], limit: 20, // page size offset: 0 // page number }) // Returns `SolanaNFTExtended[]` export interface SolanaNFTExtended { name: string; sellerFeeBasisPoints: number; updateAuthorityAddress: string; description: string; image: string; externalUrl: string; creators: Creator[]; owner: Owner; attributes: MetadataAttributes[]; listings: SolanaNFTListing[]; }

fetchNFTsByUpdateAuthorities

Fetch NFTs By Update Authorities. Returns a detailed payload of all NFTs whose updateAuthorities are provided

const nftsQueryResult: SolanaNFTExtended[] = await mirrorworld.fetchNFTsByUpdateAuthorities({ updateAuthorities: [`Hc2My3GQCQTXTjV34Pi1pQGYUeckT1mEcMRiZZaH7Ydr`], limit: 20, // page size offset: 0 // page number }) // Returns `SolanaNFTExtended[]` export interface SolanaNFTExtended { name: string; sellerFeeBasisPoints: number; updateAuthorityAddress: string; description: string; image: string; externalUrl: string; creators: Creator[]; owner: Owner; attributes: MetadataAttributes[]; listings: SolanaNFTListing[]; }

fetchNFTsByOwnerAddresses

Fetch NFTs By Update Authorities. Returns a detailed payload of all NFTs whose owners are provided

const nftsQueryResult: SolanaNFTExtended[] = await mirrorworld.fetchNFTsByOwnerAddresses({ owners: [`Hc2My3GQCQTXTjV34Pi1pQGYUeckT1mEcMRiZZaH7Ydr`], limit: 20, // page size offset: 0 // page number }) // Returns `SolanaNFTExtended[]` export interface SolanaNFTExtended { name: string; sellerFeeBasisPoints: number; updateAuthorityAddress: string; description: string; image: string; externalUrl: string; creators: Creator[]; owner: Owner; attributes: MetadataAttributes[]; listings: SolanaNFTListing[]; }

fetchNFTMarketplaceActivity

Fetch Solana NFT Marketplace Activity for an NFT

const mintAddress = "Ct1GvgpBzzhMtKb7nKc3U3kouPA3fHncAahPY1HthB9E" const activityEvents: SolanaNFTAuctionActivitiesPayload[] = await mirrorworld.fetchNFTMarketplaceActivity(mintAddress) // Returns `SolanaNFTAuctionActivitiesPayload[]` export interface SolanaNFTAuctionActivitiesPayload { mintAddress: string; auctionActivities: SolanaNFTAuctionActivity[]; tokenTransfers: SolanaNFTTransfersEntity[]; }

Accessors

user

Get current user object

const user: UserWithWallet = mirrorworld.user export interface UserWithWallet { id: number; eth_address: string; sol_address: string; email: string; email_verified: boolean; username: string; createdAt: string; updatedAt: string; wallet: { eth_address: string; sol_address: string; }; }

clusterEnv

Get instance's environment

const clusterEnv: ClusterEnvironment = mirrorworld.clusterEnv export enum ClusterEnvironment { mainnet = 'mainnet', testnet = 'testnet', local = 'local', }

wallet

Get current user's wallet

const wallet: Wallet = mirrorworld.wallet export interface Wallet { eth_address: string; sol_address: string; }

tokens

Get current user tokens

const tokens: ISolanaToken[] = mirrorworld.tokens export interface ISolanaToken { ata: string; mint: string; amount: string; }

transactions

Get current user transactions

const transactions: ISolanaTransaction[] = mirrorworld.transactions export interface ISolanaTransaction { blockTime: number; meta: Meta; slot: number; transaction: Transaction; }

nfts

Get current user's nfts

const nfts: SolanaNFTExtended[] = mirrorworld.nfts export interface SolanaNFTExtended { name: string; sellerFeeBasisPoints: number; updateAuthorityAddress: string; description: string; image: string; externalUrl: string; creators: Creator[]; owner: Owner; attributes: MetadataAttributes[]; listings: SolanaNFTListing[]; }

isLoggedIn

Checks whether the current user is logged in

const isLoggedIn: boolean = mirrorworld.isLoggedIn

Events

The SDK also emits events when specific events happen in the SDK

export type MirrorWorldEvents = { 'login:email': UserWithWallet; login: unknown; logout: unknown; ready: undefined; 'auth:refreshToken'?: string; 'update:user'?: undefined; };

You can listen the these events using the on() method. For example To listen to the login:email event, we invoke the following event:

mirrorworld.on("login:email", (user) => { console.log("Logged in User", user) })

Edit this page on GitHub

On this page