Skip to main content

πŸ”– Attestation

In this section, you'll play the role of the attester:

  • You'll take a RequestForAttestation object;
  • Attest it;
  • Store the attestation on the chain (more specifically only its hash, we'll get to that);
  • Build the Credential object which will be send back to the claimer.

Request KILT tokens

When writing the hash of attestations on the blockchain, attesters have to pay the angel’s share (gas or transaction fee) and the deposit in KILT Tokens. So you'll need tokens to attest a claim.

If you haven't already requested KILT tokens, go to the (element and discord) and request tokens for your <attesterAddress>.

Sadly these are just play tokens, not real money.

Create a file

Create a new file attestation.js. All of the code for this step needs to go into this file.

Code: validate the RequestForAttestation object

In a real-life setup, as an attester you would directly receive a RequestForAttestation from a claimer.

In this tutorial, you can either:

  • Take the RequestForAttestation object you've generated in the previous step as a claimer;
  • Or if you're in a workshop, ask another participant to send you their RequestForAttestation object.

In the following, we'll refer to it as <requestForAttestationJSONString>.

Paste the following code in attestation.js (make sure to replace <attesterMnemonic>, <attestersFullDid>, <attestersAccount> and <requestForAttestationJSONString> with the relevant objects):

import * as Kilt from '@kiltprotocol/sdk-js'

export function main(encodedRequestForAttestation: string) {
const requestForAttestationStruct = JSON.parse(encodedRequestForAttestation)

return Kilt.RequestForAttestation.fromRequest(requestForAttestationStruct)

To check if the object is valid, you can check the data against the CTYPE and check if the signature is valid.

import * as Kilt from '@kiltprotocol/sdk-js'

export async function main(
requestForAttestation: Kilt.RequestForAttestation
): Promise<boolean> {
await Kilt.connect()

const isDataValid = requestForAttestation.verifyData()
const isSignatureValid = await requestForAttestation.verifySignature()
console.log('isDataValid: ', isDataValid)
console.log('isSignatureValid: ', isSignatureValid)

await Kilt.disconnect()

return isDataValid && isSignatureValid

Code: create an Attestation

Now is time to interact with the chain, in order to store an attestation on there.
Append the following code to your main function inside attestation.js.

import * as Kilt from '@kiltprotocol/sdk-js'

export async function main(
attester: Kilt.KeyringPair,
attesterFullDid: Kilt.Did.FullDidDetails,
requestForAttestation: Kilt.RequestForAttestation,
keystore: Kilt.Did.DemoKeystore
): Promise<Kilt.Credential> {
await Kilt.connect()

// build the attestation object
const attestation = Kilt.Attestation.fromRequestAndDid(

// store the attestation on chain
const tx = await
const authorizedTx = await attesterFullDid.authorizeExtrinsic(
await Kilt.BlockchainUtils.signAndSubmitTx(authorizedTx, attester, {
resolveOn: Kilt.BlockchainUtils.IS_FINALIZED,
console.log('Attestation saved on chain.')

// the attestation was successfully stored on the chain, so you can now create the credential object
const credential = Kilt.Credential.fromRequestAndAttestation(
// log the Credential so you can copy/send it back to the claimer
console.log('CredentialJSONString:\n', JSON.stringify(credential))

// disconnect from the chain
await Kilt.disconnect()
console.log('Disconnected from KILT testnet')
return credential


Run the code by running this command in your terminal, still within your kilt-rocks directory:

node attestation.js

You should see in your logs:

  • true and true if the signature and data are valid (they should be);
  • The block hash in which the transaction was finalized;
  • The Credential object.

Copy the Credential object, you'll need it soon.

Your job as an attester is done: you've successfully attested a claim, written the attestation hash onto the chain, and prepared the Credential object for the claimer.