Authentication
To connect to the XP API, you will need an authentication key provided by the XP team.
You can request one here -> [email protected]
- 1.You must be approved with a valid api key to submit scores to this endpoint.
- 2.For a score to take effect, you must also sign the update with a wallet address that is approved as an "owner" or "updater" for that specific XP Project Id. (Can be added in your dashboard/Directly on contract)
Connect using the "X-API-KEY" header in your request
"X-API-KEY":"<api-key>"
let myHeaders = new Headers();
let message = Date.now().toString();
let signatureObject = await web3.eth.accounts.sign(message, <PRIVATE_KEY>);
let signature = signatureObject.signature;
//Headers
myHeaders.append("X-API-KEY","<key>");
myHeaders.append("Content-Type", "application/json");
//Send to API
const body = JSON.stringify({
"updateId": updateId,
"projectId": <PROJECT_ID>,
"actionName": <action-name>,
"scoreType": <scoreType>,
"targetWallet": <targetAddress>,
"signature": signature,
"message": message
})
const requestOptions = {
method: 'POST',
headers: myHeaders,
body: body,
redirect: 'follow'
};
let response = await fetch('https://api.xp-protocol.io/update-score, requestOptions).then(async (response) => ({ status: response.status, value: await response.text() }));
Last modified 3mo ago