Arkham X Chainlink is live!

November 10, 2023

Arkham x Chainlink:
How to use Arkham labels on-chain with Chainlink Functions

Last month, we announced our collaboration with Chainlink aimed at bringing Arkham data on-chain. Today, we’ve gone live with the first implementation of this integration, starting with our labeling endpoint—the part of our API that takes a blockchain address as input, references our database, and then outputs any applicable intelligence from the Arkham database, namely, the real-world owner of the address.

With Chainlink Functions, you can now use these labels on-chain and easily incorporate Arkham data into your dApp to help enable a whole new set of use cases, such as:

Here’s how:

Step 1: Sign up for Arkham API access here.

Step 2: Once you’ve received API access, you can try out using the labeling endpoint in a Chainlink Function using the Playground tool by inputting the following code:

Validate inputs to the Function -

  const address = args[0]

  if (address.length != 42) {
    throw Error("invalid address")
  }

  if (!secrets.ARKHAM_API_KEY) {
    throw Error("api key required")
  }


Request Arkham’s /intelligence/address/:address/all endpoint -

  const url = `https://api.arkhamintelligence.com/intelligence/address/${address}/all`
  const resp = await Functions.makeHttpRequest({url, headers: {'API-Key': secrets.ARKHAM_API_KEY}})
  const data = resp["data"]
  if (resp.error) {
    console.error(error)
    throw Error("Request failed")
  }


Extract the entity from the response -

The response will be a map from chain ID (e.g. “ethereum”) to an address object. If Arkham has attributed that address to an entity, the address object will contain an arkhamEntity field. Iterate over the mapping to find the first chain-address combo with that field present. Return that entity ID.

  let entityId = ""

  for (const [chain, intel] of Object.entries(data).sort()) {
    if (intel.arkhamEntity !== undefined) {
      entityId = intel.arkhamEntity.id
      break
    }
  }

  return Functions.encodeString(entityId)


Test the code is working properly -

You can test the code above by entering an address and verifying that the output entity ID is what we expect to see. For example, 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 belongs to Vitalik Buterin. When you use this as your input address, you should expect to see “vitalik-buterin” as the output.

How to call an API using Chainlink Functions -

Experienced developers can use the Chainlink Functions NPM package in their own JavaScript or TypeScript project. Chainlink also provides an example tutorial on how to call an API with HTTP query parameters here. You’ll want to modify source.js with the source code above. Additionally, you may need to modify request.js with different argument variables such as ARKHAM_API_KEY.

To enable access to APIs that require authentication credentials, Chainlink Functions helps enable users to provide encrypted secret values, which can be used when making a Functions request. Please reference one of the following guides for approaches to securely encrypting your Arkham API key for use with Chainlink Functions:

Need more support with your Chainlink Function integration? Reach out to Chainlink Labs to speak to an expert: https://chain.link/contact

Bringing our data on-chain with Chainlink is an important step towards advancing transparency in crypto. Reach out to us on X (Twitter) at @ArkhamIntel if you have an idea for an implementation and we’d be happy to help you bring it to life. Or if you’ve already built one, we’d love to bring attention to it. We can’t wait to see the innovative ways you put our labels to work!

References: