import React, { Component } from "react";
import factory from "../ethereum/factory";
import { ethers } from "ethers";
class CampaignIndex extends Component {
render() {
return <div>campaigns{this.props.campaigns}</div>;
}
}
export async function getServerSideProps() {
const campaigns = await factory.getDeployedCampaigns();
await campaigns.wait();
console.log(campaigns);
return { campaigns };
}
export default CampaignIndex;
-> factory is an instance of deployed contract
-> getDeployedCampaigns() is a function in deployed contracts which returns an array of addresses
-> used Next.js v12.3.1
When I call getDeployedCampaigns() from getServerSideProps() block, it returns an error - bad request, but if I call above function from elsewhere - except that block, I am getting expected results. I don't know why next.js is behaving this way.