Creating an Attestation (Solidity)

Now that you have created your schema with a schema hook address set, you must provide attestation data in the correct format that you set in your schema, or else verification will fail. If you are using the NPM SDK, we perform validation for you before the transaction call is sent. However, none of these safeguards exist when interacting with Sign Protocol directly from solidity.

Our simple schema only needs a uint256. We will use abi.encode to encode this number. Make sure that variables are provided in the same order they are set in the schema, which is the same order they will be decoded in your schema hook and on the SignScan attestation explorer.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ISP } from "@ethsign/sign-protocol-evm/src/interfaces/ISP.sol";
import { Attestation } from "@ethsign/sign-protocol-evm/src/models/Attestation.sol";
import { DataLocation } from "@ethsign/sign-protocol-evm/src/models/DataLocation.sol";

contract DataAttester is Ownable {
    ISP public spInstance;
    uint64 public schemaId;

    constructor() Ownable(_msgSender()) { }

    function setSPInstance(address instance) external onlyOwner {
        spInstance = ISP(instance);
    }

    function setSchemaID(uint64 schemaId_) external onlyOwner {
        schemaId = schemaId_;
    }

    function attest(address recipient, uint256 someNumber) external onlyOwner returns (uint64) {
        bytes[] memory recipients = new bytes[](1);
        recipients[0] = abi.encode(recipient);
        Attestation memory a = Attestation({
            schemaId: schemaId,
            linkedAttestationId: 0,
            attestTimestamp: 0,
            revokeTimestamp: 0,
            attester: address(this),
            validUntil: 0,
            dataLocation: DataLocation.ONCHAIN,
            revoked: false,
            recipients: recipients,
            data: abi.encode(someNumber)
        });
        return spInstance.attest(a, "", "", "");
    }
}

Last updated

Logo

Copyright Sign 2021-2024