En el archivo game.js tenes que importar la libreria de la siguiente manera
import {
DgWorldMarketplace,
MarketplaceOptions,
} from "dg-world-marketplace-sdk";
y luego instanciar la clase DgWorldMarketplace
const opts: MarketplaceOptions = {
previewEnv: 'prod' as any,
network: 'MATIC' as any,
engine,
zoneId: YOUR_ZONE_ID,
debug: true,
lang: {
noFundsTitle: "No Funds",
noFundsDesc: "Sorry, you do not have enough ICE",
noFundsButton: "No Funds",
approveIceTitle: "Approve ICE",
approveIceDesc:
"Authorize the Store contract to operate ICE on your behalf",
approveIceWait: "Please wait.\nThe transaction is being processed",
approveIceRejected:
"You need to authorize the Store contract to be able to buy this item",
buyFor: "Buy for:",
authorize: "Authorize",
reject: "Reject",
transactionProccessing: "Please wait.\nThe transaction is being processed",
purchaseSucceed:
"Purchased succeed!\nYou will need to refresh the page to see the wearable in your backpack.",
purchaseFailed: "Purchased failed.\nPlease try again.",
wait: "Wait",
buy: "Buy",
openPaymentLink: "Open Payment Link",
nftNotAvailable: "NFT not available",
},
};
const dgMarketplace = new DgWorldMarketplace(opts);
Tener en cuenta que Decentraland sdk solo soporta un canvas. por lo que si se quiere usar un canvas propio y no el que genera el Marketplace SDK tenemos que pasarle dicho canvas por parametros al momento de instanciar el Marketplace SDK
Despues de instanciar la clase podemos escuchar los distintos eventos que querramos
// emited when the sdk is ready to connect to the blockchain
dgMarketplace.on('web3Ready', () => {
log('web3Ready')
})
// emited after the sdk connect to the websocket
dgMarketplace.on('websocketsReady', () => {
log('websocketsReady')
})
// emited after the sdk fetch the variables
dgMarketplace.on('variablesReady', () => {
log('variablesReady')
log(dgMarketplace.getVariables())
})
// emited last, when all the sdk is ready
dgMarketplace.on('ready', () => {
log('ready')
})
// emited when any error happens, notice that err could be null or undefined, depending on the error
dgMarketplace.on('error', (err) => {
log(err)
})