Creating an Attestation (Solidity)¶
Attestation data must match the format set in your schema, or verification will fail. The NPM SDK validates data before it sends the transaction, but there is no such check when you call Sign Protocol directly from Solidity.
This schema only needs a uint256, encoded with abi.encode. Provide variables in the order they are set in the schema; your schema hook and the SignScan attestation explorer decode them in that order.
// 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, "", "", "");
}
}