Endpoints

XP

This endpoint sends a create project request to the XP contract

POST https://api.xp-protocol.io/create-project

This should be the first step into the XP ecoysystem

Headers

NameTypeDescription

X-API-KEY

<Your-Key>

Get an API key from the Huddln team

Content-Type*

application/json

Request Body

NameTypeDescription

projectId*

0xf0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b

A 32 Byte string of what you would like the project ID to be. This is not updateable and can only be chosen once.

name*

test

Name this project with something that closely aligns to your company's name.

inputActions*

[{"name":"bought","points":200,"direction":0}]

An array of actions and their properties, use the examlpe provided to construct this object.

owners*

["0x0000000000000000000000000000000000000000","0x0000000000000000000000000000000000000001"]

An array of wallet addresses as strings that have full authority over this project,

updaters*

["0x0000000000000000000000000000000000000000","0x0000000000000000000000000000000000000001"]

An array of wallet addresses as strings that have permissions to call the updateScore() method for this project. This is used so that your backend can update the scoring system in a more scalable manner.

Update score of a wallet address

POST https://api.xp-protocol.io/update-score

In the XP ecosystem this function should be called any time you want to trigger a score change.

Request Body

NameTypeDescription

updateId*

0x2413fb3709b05939f04cf2e92f7d0897fc2596f9ad0b8a9ea855c7bfebaae892

A unique / semi unique (depending on the use-case) 32 byte string to associate with this update.

projectId*

0xf0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b

The 32 byte string ID of the project associated with this update.

actionName*

bought

A string of the action you would like to trigger against the particular wallet address. This action must already exist in the project's list of actions.

scoreType*

reputation

A string that indicates which score type you would like this action to accumulate on. This score type must already exist within the project.

targetWallet*

0xE6F7e0aDD15c665f5AC2B0eeDFd2e8578EF2bf8A

The address as a string that you would like to update the score on.

signature*

<0x....>

Create a signature from the message "${Date.now().toString()}" , A full example is provided below.

message*

1656535069845

A string generated from JS Date.now().toString(), this is a string that represents the current epoch time in milliseconds.

{
    // Response
}

More endpoints coming soon...

Example Request

The below request demonstrates how to perform a POST call to the /update-score endpoint with an X-API-KEY & Signature provided by either an "updater" or an "owner" of the project.

let myHeaders = new Headers();
let message = Date.now().toString();
let signatureObject = await web3.eth.accounts.sign(message, <PRIVATE_KEY>); //Private key of a wallet that is either an Updater or an Owner of the current project.
let signature = signatureObject.signature;

//Headers
myHeaders.append("X-API-KEY","<key>");
myHeaders.append("Content-Type", "application/json");
  
  //UpdateId, should be unique, duplicate updateIds are ignored and do will not update the target address's score.
  ///think of an updateId as a unique transaction.
 let updateId = targetAddress.toString()':'+ Date.now().toString()
 let id = '0x' + sha256(updateId).toString(); // 0x to signify its a bytes32
  //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() }));
c

Last updated