EVM Smart Contracts
Step 1: Initialize new hardhat project
yarn init -y
# yarn initialization flow
yarn add --dev hardhat
yarn hardhat init
# Hardhat initialization flow (select TypeScript project)Step 2: Write a contract that verifies an update in the transaction
// SPDX-License-Identifier: BSL1.1
pragma solidity ^0.8.20;
interface IPullMarketplace {
struct PriceUpdate {
uint256 price;
uint256 timestamp;
}
function verifyWithFee(
bytes calldata updateData,
bytes32 feedKey
) external payable returns (PriceUpdate memory);
function getUpdateFee(uint256 nUpdates) external view returns (uint256);
}
contract PullVerifier {
IPullMarketplace public pullMarketplace;
uint public latestPrice;
uint public latestTimestamp;
constructor(address _pullMarketplace){
pullMarketplace = IPullMarketplace(_pullMarketplace);
}
// @notice function that verifies feed from provided update PAYG through PullMarketplace and stores update data
function VerifyPAYG(bytes calldata updateData, bytes32 feedKey) external{
// Calculate required fee
uint256 fee = pullMarketplace.getUpdateFee(1);
// Verify the update
IPullMarketplace.PriceUpdate memory priceUpdate = pullMarketplace.verifyWithFee{value: fee}(updateData, feedKey);
// store update data
latestPrice = priceUpdate.price;
latestTimestamp = priceUpdate.timestamp;
}
// @notice deposit native tokens for fee coverage
receive() payable external {}
}
Step 3: Deploy the contract
Step 4: Understanding update format and Finalized Data API
Step 5: Send a transaction with the update data
Last updated