Skip to main content

Step 2: Prepare Smart Contract

Let’s prepare your smart contract for integration with PureFi.

1. Import the IPureFiVerifier Interface

Add the import statement for the IPureFiVerifier interface to your contract. This interface provides access to the validatePayload method.

import {IPureFiVerifier} from "./PureFi/interfaces/IPureFiVerifier.sol";

The file path may vary depending on your project structure. Ensure you point to the correct location of the interface from the SDK.

2. Declare a Variable for PureFiVerifier

Define a variable to store the address of the PureFiVerifier contract. This allows your contract to call its methods.

IPureFiVerifier public verifier;

3. Initialize the PureFiVerifier Address

Set the PureFiVerifier address during contract deployment. You can do this via a constructor or an initialization function (if using an upgradeable contract, e.g., with OpenZeppelin Upgradeable).

  • Example for a standard contract:
constructor(address _verifier) {
verifier = IPureFiVerifier(_verifier);
}
  • Example for an upgradeable contract:
function initialize(address _verifier) external initializer {
verifier = IPureFiVerifier(_verifier);
// Additional initialization
}

You’ll obtain the PureFiVerifier address from the PureFi documentation or team, as it depends on the network (e.g., Ethereum, BSC, etc.).

4. (Optional) Add a Function to Update the Address

Include a function to update the PureFiVerifier address if it changes in the future. This enhances flexibility for long-term projects.

function setVerifier(address _verifier) external onlyOwner {
require(_verifier != address(0), "Invalid verifier address");
verifier = IPureFiVerifier(_verifier);
}

Here, the onlyOwner modifier (e.g., from OpenZeppelin Ownable) restricts this action to the contract owner.