Skip to main content

Quick Start

image

Quickstart

This section walks you through deploying and integrating a Primus contract into your Solidity project.

Install the contract

When setting up your smart contract project, you need to pull out the smart contract library first.

  • Using Hardhat: npm install @primuslabs/zktls-contracts

  • Using Foundry: forge install primus-labs/zktls-contracts

Deploy a smart contract

Deploy the following contract to any EVM-compatible network of your choice. For this walkthrough, we'll use Ethereum as an example.

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

// if you are using foundry, you can use the following conf:
// you can edit import information like this in your local project remappings.txt:
// @primuslabs/zktls-contracts=lib/zktls-contracts/

import { IPrimusZKTLS, Attestation } from "@primuslabs/zktls-contracts/src/IPrimusZKTLS.sol";
contract AttestorTest {
address public primusAddress;

constructor(address _primusAddress) {
// Replace with the network you are deploying on
primusAddress = _primusAddress;
}

function verifySignature(Attestation calldata attestation) public view returns(bool) {
IPrimusZKTLS(primusAddress).verifyAttestation(attestation);

// Business logic checks, such as attestation content and timestamp checks
// do your own business logic
return true;
}
}

On-chain Interactions

The following code helps developers interact with the Test example or Production example contracts on-chain. This can be done using the zkTLS SDK after completing the smart contract development and deployment.

   ....
....

//start attestation process
const attestation = await primusZKTLS.startAttestation(signedRequestStr);
console.log("attestation=", attestation);

if (verifyResult === true) {
// Business logic checks, such as attestation content and timestamp checks
// Do your own business logic

// Interacting with Smart Contracts
// Set contract address and ABI
const contractData = {"YOUR_CONTRACT_ABI_JSON_DATA"};
const abi = contractData.abi;
const contractAddress = "YOUR_CONTRACT_ADDRESS_YOU_DEPLOYED";
// Use ethers.js connect to the smart contract
const provider = new ethers.providers.JsonRpcProvider("YOUR_RPC_URL");
const contract = new ethers.Contract(contractAddress, abi, provider);

try {
// Call verifyAttestation func
const tx = await contract.verifySignature(attestation);
console.log("Transaction:", tx);
} catch (error) {
console.error("Error in verifyAttestation:", error);
}
} else {
//not the primus sign, error business logic
}