2. CAS

Read Method: getAttestationUid The getAttestationUid method returns an attestation UID by recipient and schemaUid.

Parameters

  • recipient: The Address receiving the attestation.

  • schemaUid: The UID of the schema.

Returns

  • bytes32: The UID of the attestation

Read Method: getAttestation The getAttestation method returns an existing attestationʼs raw data by attestation UID.

Parameters

  • uid: The attestation UID (bytes32).

Returns Attestation: A struct with:

  • uid: The attestation UID.

  • schema: The schema UID.

  • time: The time when the attestation was created (Unix timestamp).

  • expirationTime: The time when the attestation expires (Unix timestamp).

  • revocationTime: The time when the attestation was revoked (Unix timestamp).

  • recipient: The recipient of the attestation.

  • attester: The attester/sender of the attestation.

  • revocable: Whether the attestation is revocable.

  • data: The encoded data based on the schema (bytes).

Write Method: attest The attest method creates a single attestation based on a predefined schema.

Parameters

  • schema : The schema UID (bytes32).

AttestationRequestData: A struct with:

  • recipient: Address receiving the attestation (user address of passed kyc check).

  • expirationTime: Unix timestamp when the attestation expires (uint64; 0 for no expiration).

  • revocable: Boolean indicating if the attestation can be revoked (bool).

  • data: Encoded data according to the schema (bytes).

Returns

  • bytes32: The UID of the created attestation.(emits a Attested event).

Notes

  • Ensure the schema exists in the registry.

  • Handle gas fees and potential reverts (e.g. invalid schema)

Write Method: multiAttest The multiAttest method creates multiple attestations in a single transaction for efficiency.

Parameters

  • multi: An array of structs, each containing:

  • schema: The schema UID for the batch (bytes32).

  • data: An array of AttestationRequestData structs (same as in attest).

Returns

  • bytes32[]: Array of UIDs for the created attestations.

Notes

  • All attestations in a batch must use the same schema if grouped, but the method supports multiple schemas.

  • Useful for bulk operations to save gas.

Write Method: revoke The revoke method revokes a single attestation if it was created as revocable.

Parameters

  • multi: An array of revoke structs (same as in revoke).

Returns

  • None (emits Revoked events).

Notes

  • Efficient for batch revocations.

  • Supports different schemas per revocation.

How to decode the attestation data Letʼs say the schema string is 'bool isVerified'

Solidity Example code:

struct Payload {
    bool isVerified;
}

Attestation memory attestation = cas.getAttestation(uid);
(Payload memory p) = abi.decode(attestation.data, (Payload));

TypeScript Example code:

import {ethers} from "ethers";

const result = ethers.utils.defaultAbiCoder.decode(["bool"], attestation.data)

Best Practices

  • Error Handling: Use try-catch for transactions and check for common errors like AlreadyAttested error.

  • Events: Listen for Attested and Revoked events to confirm actions.

  • Gas Optimization: Use multi-methods for batches to reduce costs.

  • Security: Validate inputs and use secure wallets. Never expose private keys in code.

  • Testing: Test on Testnet before mainnet deployment.

This integration enables robust attestation management in your dApp. If you encounter issues, consult the SC team for updates.

Last updated

Was this helpful?