How to fetch badges

You can get access to Badges connecting to TheBadge’s subgraph:

Goerli Testnet
Ethereum Mainnet

Coming soon 🚀

In the subgraph, you can request data about badges. You can search for them by using the badge's id.

For example:

query badgeById($id: ID!) {
   badge(id: $id) {
     id
     evidenceMetadataUrl
     reviewDueDate
     status
     isChallenged
     receiver {
       id
     }
     badgeType {
       id
       metadataURL
       validFor
       badgesMintedAmount
     }
   }
 }

Take into account that a badge’s id has the format: “ {ownerAddress} - {badgeTypeId} ”

Using the field: “evidenceMetadataUrl” (IPFS hash) you can obtain further information about the Badge. If you get the IPFS data from it, the JSON file that you receive has a structure like this:

{
    Columns: [],
    Values: {},
    Image:
}

On the Image field, you will get the hash of the PNG file stored in IPFS for this particular Badge. If you want to show visually a Badge, you can use the image from there. On the other hand, Values and Columns contain the evidence provided by the user to obtain it.

“Columns” represents the form fields with label, type and description, and “Values” is an object (key-value) with the form label as key and the evidence on the other side.

If you want to obtain all the badges for a particular address, you can use this:

query userBadges($ownerAddress: ID!) {
    badges(where: {requestedBy: $ownerAddress}) {
      id
      status
      reviewDueDate
      evidenceMetadataUrl
      badgeType {
        validFor
        metadataURL
        id
        badgesMintedAmount
        creator {
          creatorMetadata
        }
      }
    }
  }

If you have any questions or need further assistance, feel free to contact our team on our Discord!

Last updated