EAS 데이터 조회하기
마루 EAS에서 attestation을 읽는 방법을 안내합니다. 정식 surface인 Solidity 컨트랙트 호출, 역방향 조회용 EAS Indexer, JS/TS SDK 세 가지 경로를 다룹니다.
사전 요구사항
- 마루 테스트넷 RPC URL
- EAS / EAS Indexer 주소 (preinstall 또는 EAS 프리컴파일
getParams()로 해결)
EAS / Indexer 주소 해결
두 가지 옵션이 있습니다. 정식 preinstall 주소를 하드코딩하는 방법(
EAS = 0x1000…0007, Indexer = 0x1000…0008)은 알려진 네트워크에 적합합니다. 또는 EAS 프리컴파일의 getParams()를 호출하면 어떤 마루 네트워크에서든 수정 없이 동일한 코드로 동작합니다.import { createPublicClient, http } from "viem";
const EAS_PRECOMPILE = "0x1000000000000000000000000000000000000009";
const { eas: EAS, indexer: INDEXER } = await publicClient.readContract({
address: EAS_PRECOMPILE,
abi: easPrecompileAbi,
functionName: "getParams",
}); 방법 1 — 직접 컨트랙트 호출 (viem / ethers)
프론트엔드 dApp과 대부분의 백엔드 코드가 사용하는 기본 경로입니다. EAS 컨트랙트에
getAttestation(uid)을 호출하면 전체 Attestation struct (schema, recipient, attester, time, expirationTime, revocationTime, refUID, data)를 반환합니다.import { createPublicClient, http } from "viem";
const publicClient = createPublicClient({ transport: http(MAROO_RPC) });
const attestation = await publicClient.readContract({
address: EAS,
abi: easAbi,
functionName: "getAttestation",
args: [uid],
});
// attestation.recipient, attestation.revocationTime, attestation.expirationTime, ... 방법 2 — Indexer를 통한 역방향 조회
"사용자 X가 스키마 Y로 attest를 받았는가?" — 이때 사용하는 것이 Indexer입니다. 사용할 두 메서드는 다음과 같습니다.
각 UID를 방법 1에 넣어 실제 attestation을 가져옵니다.
getReceivedAttestationUIDCount(recipient, schemaUid)→ 저렴한 존재 확인getReceivedAttestationUIDs(recipient, schemaUid, start, length, reverseOrder)→ 페이지네이션 목록
각 UID를 방법 1에 넣어 실제 attestation을 가져옵니다.
// 1) 카운트 확인
const count = await publicClient.readContract({
address: INDEXER,
abi: indexerAbi,
functionName: "getReceivedAttestationUIDCount",
args: [recipient, schemaUid],
});
// 2) 가장 최근 5개
const uids = await publicClient.readContract({
address: INDEXER,
abi: indexerAbi,
functionName: "getReceivedAttestationUIDs",
args: [recipient, schemaUid, 0n, 5n, true /* reverseOrder */],
}); 참고: 가져온 뒤에는 폐기되거나 만료된 attestation을 필터링합니다. Indexer는 발급만 추적하고 유효성은 추적하지 않으며, PCL의 `EAS_POLICY`도 `getAttestation`에 대해 동일한 revocation/expiration 검사를 수행합니다.
방법 3 — eas-sdk (JS)
스택에서 이미 공식
@ethereum-attestation-service/eas-sdk를 쓰고 있다면 마루 EAS 주소를 가리키게 한 뒤 평소처럼 사용합니다. SDK는 getAttestation과 스키마 레지스트리 호출을 래핑합니다.const { EAS } = require("@ethereum-attestation-service/eas-sdk");
const eas = new EAS(EAS); // 정식 마루 EAS 주소
await eas.connect(provider);
const attestation = await eas.getAttestation(uid); 참고: eas-sdk는 Indexer 바인딩을 제공하지 않으므로, 역방향 조회는 방법 2처럼 viem/ethers로 Indexer를 직접 호출합니다.
방법 4 — 쉘 임시 조회용 `cast`
쉘에서 값을 즉석으로 확인하고 싶을 때 사용합니다.
# attestation 하나 가져오기
cast call $EAS "getAttestation(bytes32)" $UID --rpc-url $MAROO_RPC
# 사용자가 스키마 하의 보유 attestation 카운트
cast call $INDEXER \
"getReceivedAttestationUIDCount(address,bytes32)(uint256)" \
$RECIPIENT $SCHEMA_UID --rpc-url $MAROO_RPC