๐Ÿš€Deploying a Consumer Contract

Deploying and testing your consumer contract using Hardhat is a straightforward process, especially with the deployment scripts provided in the SEDA Hardhat Starter Kit. We've implemented a deployment script using Hardhat Ignition to simplify the steps.

Step 1: Set Up the Environment

Before deploying, ensure that your environment is configured correctly with the required .env, hardhat.config.ts, and seda.config.ts files. These files contain important variables and settings for the deployment process.

.env

The .env file holds sensitive data such as private keys and contract IDs. Ensure that you fill in the required values:

ORACLE_PROGRAM_ID=YOUR_ORACLE_PROGRAM_ID
EVM_PRIVATE_KEY=YOUR_EVM_PRIVATE_KEY
BASE_SEPOLIA_ETHERSCAN_API_KEY=YOUR_BASESCAN_API_KEY

seda.config.ts

This configuration file specifies the SedaProver contract addresses for different networks. Hereโ€™s an example for the baseSepolia network:

export interface SedaConfig {
  proverAddress: string;
}

export const networkConfigs: { [network: string]: SedaConfig } = {
  baseSepolia: {
    proverAddress: "0xcBC8a3159535BfE276ADaA8604940602e02c5457",
  }
};

Make sure you add the correct proverAddress for each network you're working with.

Hardhat Network Setup

Your Hardhat network configuration should follow the standard setup. Refer to the Hardhat documentation for detailed guidance on configuring networks in hardhat.config.ts.

Step 2: Deploy the Contract

Once your environment is set up, use Hardhat to deploy the PriceFeed contract. Ensure that youโ€™ve defined the necessary environment variables, including ORACLE_PROGRAM_ID and EVM_PRIVATE_KEY, which are essential for deployment.

Run the following command to deploy the contract using Hardhat Ignition:

npx hardhat ignition deploy ./ignition/modules/PriceFeed.ts --network baseSepolia --verify

After confirming the deployment, Hardhat Ignition will execute the deployment and provide the deployed contract address:

โœ” Confirm deploy to network baseSepolia (84532)? โ€ฆ yes
Hardhat Ignition ๐Ÿš€

Deploying [ PriceFeedModule ]

Batch #1
  Executed PriceFeedModule#PriceFeed

[ PriceFeedModule ] successfully deployed ๐Ÿš€

Deployed Addresses

PriceFeedModule#PriceFeed - 0x2b9b32E3Ea0799EBD7877Cf81e92598734616fFA

If you use the --verify flag, Hardhat will also verify the contract on the blockchain explorer, providing a link to view the verified contract code:

Verifying deployed contracts

Verifying contract "contracts/PriceFeed.sol:PriceFeed" for network baseSepolia...
Contract contracts/PriceFeed.sol:PriceFeed already verified on network baseSepolia:
  - https://sepolia.basescan.org/address/0x2b9b32E3Ea0799EBD7877Cf81e92598734616fFA#code

Step 3: Post a Data Request

Once the contract is deployed, you can start posting data requests and interacting with the PriceFeed contract.

The starter kit includes tasks to simplify this process. To view available tasks, run:

npx hardhat pricefeed --help

For example, to post a data request on Base Sepolia, run:

npx hardhat pricefeed transmit --network baseSepolia

Output:

No contract address specified, fetching from previous deployments...
Contract found: 0x2b9b32E3Ea0799EBD7877Cf81e92598734616fFA

Calling transmit() on PriceFeed at 0x2b9b32E3Ea0799EBD7877Cf81e92598734616fFA...
Transmit executed successfully.

If not specified, the script will fetch the contract address from the previous deployments.

Step 4: Read the Latest Answer

After the data request has been processed by the SEDA network, you can retrieve the result by calling the latestAnswer function. This will fetch the data from the network:

npx hardhat pricefeed latest-answer --network baseSepolia

Output:

No contract address specified, fetching from previous deployments...
Contract found: 0x2b9b32E3Ea0799EBD7877Cf81e92598734616fFA

Calling latestAnswer() on PriceFeed at 0x2b9b32E3Ea0799EBD7877Cf81e92598734616fFA
Latest Answer: 2541629952

With these steps, youโ€™ve successfully deployed, posted data requests, and retrieved results using the PriceFeed contract on the SEDA network. Combining these deployment and interaction scripts allows for a smooth integration into your application.

Last updated