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
| Method | Description | Parameters | Returns |
|---|---|---|---|
fetchAttestation | Fetches a single attestation by its address | rpc: RPC context, address: Attestation's address, config?: Fetch config | Promise<Account<Attestation>> |
fetchMaybeAttestation | Safely fetches an attestation, returns null if not found | rpc: RPC context, address: Attestation's address, config?: Fetch config | Promise<MaybeAccount<Attestation>> |
fetchAllAttestation | Fetches multiple attestations by their addresses | rpc: RPC context, addresses: Array of attestation addresses, config?: Fetch config | Promise<Account<Attestation>[]> |
fetchAllMaybeAttestation | Safely fetches multiple attestations, skips not found | rpc: RPC context, addresses: Array of attestation addresses, config?: Fetch config | Promise<MaybeAccount<Attestation>[]> |
Serialization
| Method | Description | Parameters | Returns |
|---|---|---|---|
getAttestationEncoder | Gets the encoder for attestation data | None | Encoder<AttestationArgs> |
getAttestationDecoder | Gets the decoder for attestation data | None | Decoder<Attestation> |
getAttestationCodec | Gets the codec for attestation data | None | Codec<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
discriminatorfield is used internally and should not be modified - The
nonceprovides a unique identifier for each attestation credentialandschemafields link the attestation to its associated credential and schema- The
datafield contains the actual attestation data and should be properly encoded/decoded according to the schema signermust be one of the authorized signers of the associated credentialexpirydetermines when the attestation becomes invalidtokenAccountlinks 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