DEV Community

Cover image for Understand Attestations! Ultimate Guide📚
Ahmed Castro for Filosofía Código EN

Posted on • Edited on

Understand Attestations! Ultimate Guide📚

This is the ultimate guide on attestations. What are they? What are they used for? Do they matter? We'll go from 0 to 100% with practical and relevant examples for users and developers. Why am I making this article? I believe they are not a fad but will be a fundamental part of web3 in areas such as governance, DeFi, protection against AI issues, among others. Also, in recent months, I have had direct contact with the creators of EAS to better understand this topic in depth. So I invite you to read the article to the end where I will be sharing advanced tips.

First Use Cases

EAS has already been launched on Ethereum Mainnet and also on various L2s such as Optimism, Arbitrum, Scroll, Base, and Linea. Although EAS is a fairly recent project, there are a couple of applications that have already launched or are about to launch. The one that caught my attention the most is the integration of Gitcoin Passport, which will simplify the process of proving your humanity. Another interesting use case is how EAS can help Coinbase comply with the complexity of regulation in the United States through on-chain verification on Base. And moving on from identity, we have Optimism RPGF v3 that used EAS to register Badge Holders, applications and more. I love this example becuase I used it and wasn't even aware that EAS was the backbone.

Future Use Cases

I share with you the most relevant future use cases below:

  • Proof of trade, to build on-chain reputation and open up possibilities for collateral-free loans or access to different types of derivatives.
  • Legaltech, RWA, letters of intent. I previously worked in legaltech in web2 and see how EAS can improve the standard of validity and backing for all types of legal documents.
  • Decentralized identity graphs, reputation proofs, anti-Sybil mechanisms.
  • Proof of humanity, differentiation between AI and humans, anti-deepfake proofs.

These are my favorite use cases; for more use cases, check out this official ideas list.

Let's Create an Attestation from the Website

You can create an attestation based on an existing schema or create your own. Schemas define the format in which attestations will be made, and in this case, we will use the Is Human schema to attest that the owner of a certain address is human. For this example, you only need to connect your Metamask wallet (or any wallet) to Scroll Sepolia, then enter the address you want to attest and click Make attestation. You can choose whether you want the off-chain attestation, i.e., free, obtained only by signing a transaction. Alternatively, you can choose to make it on-chain and pay for the transaction to make it public and connect it to smart contract logic. In this case, you will need to obtain funds in Scroll Sepolia through a Scroll Sepolia Faucet.

How to make an Attestation Using EAS Scan easscan

Advanced Example: Swap Attestations

This contract attests swaps from WETH to GHO in Uni V3 in Scroll Sepolia. It's an example that can help you understand how to integrate EAS into any protocol autonomously, all through Smart Contracts. To test it, you can deploy this contract and call the swap() function, passing the amount of WETH you want to exchange. Then, you can view your attestation in the corresponding schema on EAS Scan. Remember that you need to have WETH in advance, which you can obtain through the deposit() function here.

// SPDX-License-Identifier: MIT

pragma solidity 0.8.23;

import { IEAS, AttestationRequest, AttestationRequestData, RevocationRequest, RevocationRequestData } from "@ethereum-attestation-service/eas-contracts/contracts/IEAS.sol";
import { NO_EXPIRATION_TIME, EMPTY_UID } from "@ethereum-attestation-service/eas-contracts/contracts/Common.sol";

struct ExactInputSingleParams {
    address tokenIn;
    address tokenOut;
    uint24 fee;
    address recipient;
    uint amountIn;
    uint amountOutMinimum;
    uint160 sqrtPriceLimitX96;
}

interface IUniswapV3Router {
    function exactInputSingle(
        ExactInputSingleParams calldata params
    ) external payable returns (uint amountOut);
}

interface IERC20 {
    function totalSupply() external view returns (uint256);
    function balanceOf(address account) external view returns (uint256);
    function transfer(address to, uint256 value) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);
    function approve(address spender, uint256 value) external returns (bool);
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}

contract SwapAttestation
{
    address WETH = 0x5300000000000000000000000000000000000004;
    address GHO  = 0xD9692f1748aFEe00FACE2da35242417dd05a8615;
    address uniswapRouter = 0x17AFD0263D6909Ba1F9a8EAC697f76532365Fb95;
    uint24 poolFee = 500;// 100 500 3000 10000
    address easAddress = 0xaEF4103A04090071165F78D45D83A0C0782c2B2a;
    bytes32 schema = 0x5312f94781cdc373a4f16ddb71e8aee048bc0e3fac0819ca0258cc170c646a1d;

    function swap(uint amountIn) public
    {
        IERC20(WETH).transferFrom(msg.sender, address(this), amountIn);
        IERC20(WETH).approve(uniswapRouter, amountIn);
        ExactInputSingleParams memory params =
            ExactInputSingleParams({
                tokenIn: WETH,
                tokenOut: GHO,
                fee: poolFee,
                recipient: msg.sender,
                amountIn: amountIn,
                amountOutMinimum: 0,
                sqrtPriceLimitX96: 0
            }
        );
        uint amountOut = IUniswapV3Router(uniswapRouter).exactInputSingle(params);

        IEAS(easAddress).attest(
                AttestationRequest({
                    schema: schema,
                    data: AttestationRequestData({
                        recipient: msg.sender,
                        expirationTime: NO_EXPIRATION_TIME,
                        revocable: false,
                        refUID: EMPTY_UID,
                        data: abi.encode(WETH, GHO, amountIn, amountOut),
                        value: 0 // No value/ETH
                    })
                })
            );
    }
}
Enter fullscreen mode Exit fullscreen mode

What else can I do with EAS

Now that we experimented with attestations, let's explore what else we can do with them by looking at some examples.

  • You can create schemas from code or from EAS Scan.
  • You can make revocable attestations.
  • You can set up callbacks to execute any code after each attestation through Resolvers. This can help automating any type of execution and connecting EAS with the broader smart contract ecosystem.
  • You can me expirable attestations.
  • You can verify attestations offchain, for free.

Intersting recent EAS developments

Before designing your attestations, make sure of this

Recently, while designing my attestations, I had the opportunity to talk with the EAS development team. I showed them a design of a schema very similar to the one below, regarding book rating attestations.

  • Book Rating Schema
    • Book name
    • Author name
    • Rating

The EAS team warned me that when designing attestations, in some cases is best to create "Attestations of attestations" to make attestations more composable and also helps saving gas. They recommended creating 2 schemas as detailed below:

  • Book Schema
    • Name
    • Author name
  • Book Rating Schema
    • Book UID
    • Rating

Where Book UID is a reference passed as the refUID field. It represents an existing attestation of Book Schema. This makes it easier to index information and search for all attestations of a book. Additionally, it saves gas by not storing the details of each book (Author and Name) for each attestation.

Thank you for reading this article!

Follow me on dev.to and on Youtube for everything related to Blockchain development.

Top comments (1)

Collapse
 
3canfreekit profile image
Michael Bennett

Cool so far, Lets cook