JSPM

  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q70331F
  • License MIT

Client for quests

Package Exports

  • dcl-quests-client

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dcl-quests-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Decentraland Quests Client

This library is intended to be used with the Decentraland Quests Server, which is responsible of keeping track of active quests and the progress made by each player.

Usage

First, you need to create a client. If you have access to the signature provider, you can use this:

import { QuestsClient } from 'dcl-quests-client'
import { Authenticator, IdentityType } from 'dcl-crypto'

let identity: IdentityType

const questsClient = new QuestsClient({
  baseUrl: 'https://quests-api.decentraland.io',
  authChainProvider: (payload) => Authenticator.signPayload(identity, payload)
})

You can use dcl-crypto (not included with this library) for signing the payload. But any valid auth chain for an ethereum address should be ok.

If not, you can provide a custom fetch function that injects the headers. The next example uses SignedFetch from the Decentraland SDK:

import { QuestsClient } from "dcl-quests-client/quests-client-amd";
import { signedFetch } from "@decentraland/SignedFetch";

const client = new QuestsClient({
  baseUrl: "https://quests-api.decentraland.io",
  fetchFn: signedFetch,
});

Then you can make requests:

  const { status: httpStatus, body: quests } = await questsClient.getQuests()

  console.log(quests) // A list of quests available for the player (started or not)

  const { status: httpStatus, body: details } = await questsClient.getQuestDetails(questUuid)

  console.log(details) // Details of a particular quest (same as above, but for only one quest)

  const { status: httpStatus, body: detailsStartedQuest } = await questsClient.startQuest(questUuid)

  console.log(detailsStartedQuest) // Same as above. The quest is now started for this player

  import { ProgressData } from 'dcl-quests-client'

  let progressData: ProgressData

  const { status: httpStatus, body: details } = await questsClient.makeProgress(questUuid, taskUuid, progressData)

  console.log(details) // Same as above. The quest has now made some progress for this player