Attestation Creation¶
Save your schema's ID, because the rest of the tutorial refers to the schema by it. If you skipped the previous step, use this schema (Schema ID: onchain_evm_84532_0x34). You use its on-chain ID, 0x34, when creating an attestation.
Creating an attestation¶
You can create an attestation with the NPM SDK or by calling the Smart Contract for your network directly.
Smart contract interaction¶
Warning
NOTE: If you selected a data storage option that is not directly on-chain (such as Arweave/IPFS), your schema will require Hybrid Attestations. The SDK handles this for you, but if you call Sign Protocol smart contracts directly, pass an encoded Content ID (CID) as data when creating a hybrid attestation.
The following function takes a contract's message string and the address of the person who signed it. Get the Contract Address from the Address Book and the latest ABI from Etherscan.
import { Web3Provider } from "@ethersproject/providers";
import { BigNumber, Contract, ethers } from "ethers";
async function createNotaryAttestation(contractDetails: string, signer: string) {
let address = "0x..."; // Alice's address. Will need Alice's account to send the tx.
let schemaData = ethers.utils.defaultAbiCoder.encode(
["string", "address"],
[contractDetails, signer]
);
// Standard setup for the contract
const provider = new ethers.providers.JsonRpcProvider(
// Get an RPC URL (such as an infura link) to connect to the network
getProviderUrl(84532)
);
// Get the contract address from the Address Book in docs.sign.global
const contract = new Contract(CONTRACT_ADDRESS(84532), ISPABI.abi, provider);
// Get the provider from the currently connected wallet
const library = new Web3Provider(await connector.getProvider());
// Create writable contract instance
const instance = contract.connect(library.getSigner() as any) as Contract;
// Send the attestation transaction
try {
await instance[
"attest((uint64,uint64,uint64,uint64,address,uint64,uint8,bool,bytes[],bytes),string,bytes,bytes)"
](
{
schemaId: BigNumber.from("0x34"), // The final number from our schema's ID.
linkedAttestationId: 0, // We are not linking an attestation.
attestTimestamp: 0, // Will be generated for us.
revokeTimestamp: 0, // Attestation is not revoked.
attester: address, // Alice's address.
validUntil: 0, // We are not setting an expiry date.
dataLocation: 0, // We are placing data on-chain.
revoked: false, // The attestation is not revoked.
recipients: [signer], // Bob is our recipient.
data: schemaData // The encoded schema data.
},
signer.toLowerCase(), // Bob's lowercase address will be our indexing key.
"0x", // No delegate signature.
"0x00" // No extra data.
)
.then(
async (tx: any) =>
await tx.wait(1).then((res) => {
console.log("success", res);
// You can find the attestation's ID using the following path:
// res.events[0].args.attestationId
})
)
.catch((err: any) => {
console.log(err?.message ? err.message : err);
});
} catch (err: any) {
console.log(err?.message ? err.message : err);
}
}
NPM SDK¶
Here is the same action with the SDK, which is simpler than calling the smart contract directly:
async function createNotaryAttestation(contractDetails: string, signer: string) {
const res = await client.createAttestation({
schemaId: "0x34",
data: {
contractDetails,
signer
},
indexingValue: signer.toLowerCase()
});
}
You can pass in every attestation field, as in the direct contract call, or leave fields blank and let the SDK fill in their defaults. createAttestation returns data in this format: