Client for quests
npm install dcl-quests-clientThis 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.
First, you need to create a client. If you have access to the signature provider, you can use this:
``typescript
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)
})
`dcl-crypto
You can use (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:
`typescript
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:
`typescript
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
``