Skip to content

API Documentation

BusyBird15 edited this page Aug 30, 2023 · 19 revisions

Quick info

  • The v2 (latest) API frontend is located at https://api.blockcoin.repl.co.
  • The API is offline if the Blockcoin server is offline, both are running from the same server.
  • "Getting a Blockcoin account" is done by creating an account via our BlockCoin app.


All below instances must proceed the API frontend. If parameters are missing, responseCode of 404 is returned. If parameters are invalid or the server had an error, responseCode of 500 will be returned.

/balance/{user} - Get the current BlockCoin balance of a user

Inputs:

  • user: the username of the user to get the balance of.

Result:

{
    "balance": float,
    "url":sring,
    "username": string
    }
  • balance: the balance of the user.
  • url: the URL of the json
  • username: the username of the balance that was requested




/ping - Ping the server to see if it is alive

Inputs: none

Result:

{
    "status": "ok",
    }
  • status: Always "ok", if there is no response in five seconds (the recommended timeout) then the server is offline.




/friends/{user}/{password} - Get the friends of the user

Inputs:

  • user: the username of the user to get the friend list of.
  • password: The BlockCoin password of the user.

Result:

{
    "friends": list,
    "username": string
    }
  • friends: A list where each element is a username of the friends of the username.
  • username: The username of the user that belongs to the friend list.




/transaction/{password}/{from}/{to}/{amount} - Perform a BlockCoin transaction [LEGACY]

NOTE: This still works, though it is not the preferred way to perform a transaction.

Inputs:

  • password: The BlockCoin password of the user from.
  • from: The username of the user from whom the transaction is occurring.
  • to: The user to whom the BlockCoins are being given.
  • amount: The amount of BlockCoins to give user to.

Result:

{
    "amount": float,
    "fromUser": string,
    "success": bool,
    "toUser": string
    }
  • amount: The amount of BlockCoins given to user toUser and deducted from fromUser
  • fromUser: The username of the user that performed the transaction.
  • success: true If the transaction completed, false otherwise. If success is false, - an additional parameter reason will contain a string of the error message.
  • toUser: The user that received amount of BlockCoins.




/codetransaction/{password}/{from}/{to}/{amount} - Create a BlockCoin transaction

NOTE: For security, this is an indirect transaction. When the api is called, the only thing that occurs is a random code with information is generated. The info is stored in the server, and when one uses the retrieve call, with a code, only then does the transaction occur. This way you can create a QR code for the transaction_code and have a program scan it to run the transaction.

Inputs:

  • password: The BlockCoin password of the user from.
  • from: The username of the user from whom the transaction is occurring.
  • to: The user to whom the BlockCoins are being given.
  • amount: The amount of BlockCoins to give user to.

Result:

{
    "amount": float,
    "fromUser": string,
    "success": bool,
    "toUser": string,
    "transaction_code": int
    }
  • amount: The amount of BlockCoins given to user toUser and deducted from fromUser
  • fromUser: The username of the user that performed the transaction.
  • success: true If the transaction completed, false otherwise. If success is false, - an additional parameter reason will contain a string of the error message.
  • toUser: The user that received amount of BlockCoins.
  • transaction_code: The identification of the transaction.




/retrieve/{password}/{user}/{code} - Perform a BlockCoin transaction from a code

Inputs:

  • password: The BlockCoin password of the user user.
  • user: The username of the user who is receiving the BlockCoin.
  • code: The transaction code.

Successful Result:

{
    "amount": float,
    "fromUser": string,
    "success": bool,
    "toUser": string
    }
  • amount: The amount of BlockCoins given to user toUser and deducted from fromUser
  • fromUser: The username of the user that performed the transaction.
  • success: true if the transaction completed, false otherwise. If false, see the error response for info.
  • toUser: The user that received amount of BlockCoins.

Invalid Result:

{
    "success": bool,
    "reason": string
    }
  • success: true if the transaction completed, false otherwise. If true, see the successful response for info.
  • reason: The reason for the failed transaction.




/login/{password}/{user} - Verify the correct password/username combination.

NOTE: This is generally used if you wish to create a third-party BlockCoin app or resource.

Inputs:

  • password: The password of the user.
  • user: The user attempting to login.

Result:

{
    "success": bool,
    "message": string,
    "code": int,
    "user": string
    }
  • success: true if the password/combination is correct or false otherwise.
  • message: A brief message stating the reason for the code.
  • success: The success code: 0 for correct password/username combination; 1 if the user's password is null; 2 User has not set up a password; or 3 if the password is incorrect.
  • user: The username of the user that attempted login.


/profile/{user} - Return the profile details for the user

NOTE: This is in BETA, as some parameters are never updated.

Inputs:

  • user: The BlockCoin user to return profile details for.

Result:

{
    "aboutme": string,
    "badges": array,
    "balance": float,
    "bannerColor": string,
    "exists": bool,
    "followers": array,
    "joinedOn": string,
    "pfp": string,
    "username": string
    }
  • aboutme: The text field for the user.
  • badges: A list of strings, each string will be an ID of the badge.
  • balance: The amount of BlockCoins the user has.
  • bannerColor: A string ("blue", "red", "orange", etc.) of the banner color that the user chose.
  • exists: true if this user is a registered account, false otherwise.
  • followers: A list of strings where each string is a username of the user's friends.
  • joinedOn: A human-readable date of the account creation.
  • pfp: The full URL of the profile pic.
  • username: The username of the user.




/update-profile/{user}/{password}/{aboutme}/{bannerColor}/{pfpimg} - Change the profile info of the user (BETA)

NOTE: This call has replaced the update-aboutme call.
IMPORTANT: The pfpimg must be a URL excluding the http:// or https:// preceding it (you may split text at "//"); AND you must replace all instances of "/" in the string with a hash (#). Example: from https://myurl/image/1234 to myurl#image#1234. If this is not done, error 404 will be returned or you may mess up the user's account.

Inputs:

  • user: the username of the user.
  • password: The BlockCoin password of the user.
  • aboutme: The new aboutme for the user.
  • bannerColor: The new banner color for the user. This can be text up to 8 characters.
  • pfpimg: The new URL to the PFP image, formatted as mentioned above.

Result:

{
    "success": bool,
    "reason": int
    }
  • success: true if the update was successful, otherwise false.
  • reason: The reason for success. 1 for user not found, 2 for incorrect password, 3 for aboutme containing profanity, 4 for aboutme length too long (max 250 characters, and be sure it contains no ":", "/", or "".), 5 for banner color name too long, 6 for pfp image URL too long, and 0 for success.




Contact:
For help or third-party resource requests, DM busybird15 or S4IL on Discord.
Official BlockCoin Discord server: https://discord.gg/xHFW9dejD5
Official website: https://blockcoinweb.weebly.com