🚀Contract Deployment

Deploying and testing your 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

# Optional
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: {
    // Proxy Core Address (SEDA testnet)
    proverAddress: "0xF631860f3Cb423aA14d06305083e4887e612A7f5",
  }
};

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:

bunx hardhat pricefeed deploy --network baseSepolia --verify

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

Using SEDA Core address from config: 0xF631860f3Cb423aA14d06305083e4887e612A7f5
Using Oracle Program ID from environment: 0xdc34a84ed87ce28a2e2d233aec0eddb3e005b2ac66f6a273f4681172c8e78694

Deploying PriceFeed contract...

PriceFeed deployed successfully:
- Contract Address: 0xdD0E8D708BF94938aE55976cD05Ba1984b92802b
- SEDA Core Address: 0xF631860f3Cb423aA14d06305083e4887e612A7f5
- Oracle Program ID: 0xdc34a84ed87ce28a2e2d233aec0eddb3e005b2ac66f6a273f4681172c8e78694

Deployment information saved to /workspaces/seda-starter-kit/integrations/evm-hardhat/deployments/addresses.json
Network key: baseSepolia-84532

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 contract on block explorer...
Contract contracts/PriceFeed.sol:PriceFeed already verified on network baseSepolia:
  - https://sepolia.basescan.org/address/0xdD0E8D708BF94938aE55976cD05Ba1984b92802b#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:

bunx hardhat pricefeed --help                               
Hardhat version 2.24.0

Usage: hardhat [GLOBAL OPTIONS] pricefeed <TASK> [TASK OPTIONS]

AVAILABLE TASKS:

  deploy        Deploys the PriceFeed contract
  latest        Calls the latestAnswer function on the PriceFeed contract
  transmit      Calls the transmit function on the PriceFeed contract

pricefeed: Interact with the PriceFeed contract

For global options help run: hardhat help

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

bunx hardhat pricefeed transmit --network baseSepolia

Output:

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

Calling transmit() on PriceFeed at 0x0dA473377AbcA5734b4C794b385714d5B7093E5F...

Fees (ETH):
- Request Fee: 0.0001
- Result Fee: 0.0001
- Batch Fee: 0.0001
- Total: 0.0003

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: 0x0dA473377AbcA5734b4C794b385714d5B7093E5F

Calling latestAnswer() on PriceFeed at 0x0dA473377AbcA5734b4C794b385714d5B7093E5F
Latest Answer: 2667100160

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

Was this helpful?