Attestations

Verified claims or statements in the Solana Attestation System

Attestations

An attestation represents a verified claim or statement in the Solana Attestation System. Attestations are created by authorized signers under a credential and follow a specific schema. Each attestation contains the actual data of the claim and metadata about its creation and validity.

Structure

The Attestation struct represents an attestation in the Solana Attestation System. Each attestation links to a credential, schema, and contains the attested data along with metadata about its creation and validity period.

Type Definitions

Attestation

export type Attestation = {
    discriminator: number;           // Internal discriminator
    nonce: Address;                  // Unique identifier for the attestation
    credential: Address;             // Associated credential address
    schema: Address;                 // Associated schema address
    data: ReadonlyUint8Array;       // Attestation data
    signer: Address;                 // Address of the signer who created the attestation
    expiry: bigint;                  // Expiration timestamp
    tokenAccount: Address;           // Associated token account
};

AttestationArgs

export type AttestationArgs = {
    discriminator: number;
    nonce: Address;
    credential: Address;
    schema: Address;
    data: ReadonlyUint8Array;
    signer: Address;
    expiry: number | bigint;        // Can be either number or bigint
    tokenAccount: Address;
};

Methods

Fetching Attestations

MethodDescriptionParametersReturns
fetchAttestationFetches a single attestation by its addressrpc: RPC context, address: Attestation's address, config?: Fetch configPromise<Account<Attestation>>
fetchMaybeAttestationSafely fetches an attestation, returns null if not foundrpc: RPC context, address: Attestation's address, config?: Fetch configPromise<MaybeAccount<Attestation>>
fetchAllAttestationFetches multiple attestations by their addressesrpc: RPC context, addresses: Array of attestation addresses, config?: Fetch configPromise<Account<Attestation>[]>
fetchAllMaybeAttestationSafely fetches multiple attestations, skips not foundrpc: RPC context, addresses: Array of attestation addresses, config?: Fetch configPromise<MaybeAccount<Attestation>[]>

Serialization

MethodDescriptionParametersReturns
getAttestationEncoderGets the encoder for attestation dataNoneEncoder<AttestationArgs>
getAttestationDecoderGets the decoder for attestation dataNoneDecoder<Attestation>
getAttestationCodecGets the codec for attestation dataNoneCodec<AttestationArgs, Attestation>

Usage Examples

Fetching a Single Attestation

const attestation = await fetchAttestation(rpc, attestationAddress);
console.log('Attestation nonce:', attestation.nonce);

Fetching Multiple Attestations

const attestations = await fetchAllAttestation(rpc, [attestation1Address, attestation2Address]);
attestations.forEach(attestation => console.log('Attestation:', attestation.nonce));

Safe Fetching

const attestation = await fetchMaybeAttestation(rpc, attestationAddress);
if (attestation) {
    console.log('Attestation found:', attestation.nonce);
} else {
    console.log('Attestation not found');
}

Important Notes

  • The discriminator field is used internally and should not be modified
  • The nonce provides a unique identifier for each attestation
  • credential and schema fields link the attestation to its associated credential and schema
  • The data field contains the actual attestation data and should be properly encoded/decoded according to the schema
  • signer must be one of the authorized signers of the associated credential
  • expiry determines when the attestation becomes invalid
  • tokenAccount links the attestation to a specific token account
  • Attestations can only be created by authorized signers of the associated credential
  • The attestation data must conform to the structure defined by the associated schema