dibakarsutradhar / smart-contracts

Web 3.0 smart contracts
3 stars 0 forks source link

Raffle Client - Error || Undefined - getting getEntranceFee on the client side #29

Open dibakarsutradhar opened 2 years ago

dibakarsutradhar commented 2 years ago

There's no specific error code to this problem other than just simple undefined. The problem could be generated from the Hardhat Local Node and Raffle Contract's ABI.

  1. Hardhat Local Node's accounts are not precisely synchronised with the Metamask wallet in my browser the way I'd have wanted them to be. This is something I should get fixed asap, as it's sort of creating a backlog.

  2. Current deploy scripts for generating abi.json from the Raffle.sol contract is sort of working and again not working as the generated abi format is slightly different.

02-updateUI.ts -

import * as fs from 'fs';
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { stringify } from 'querystring';
import {
  FRONT_END_ABI_FILE,
  FRONT_END_ADDRESSES_FILE,
} from '../helper-hardhat-config';

const updateUI: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
  const { ethers } = hre;
  const chainId: string = '31337';

  if (process.env.UPDATE_FRONT_END) {
    console.log('Updating Front End...');
    const raffle = await ethers.getContract('Raffle');
    const contractAddresses = JSON.parse(
      fs.readFileSync(FRONT_END_ADDRESSES_FILE, 'utf8')
    );
    if (chainId in contractAddresses) {
      if (!contractAddresses[chainId].includes(raffle.address)) {
        contractAddresses[chainId].push(raffle.address);
      }
    } else {
      contractAddresses[chainId] = [raffle.address];
    }

    fs.writeFileSync(
      FRONT_END_ABI_FILE,
      JSON.stringify(raffle.interface)
      // raffle.interface.format(ethers.utils.FormatTypes.json)
    );

    fs.writeFileSync(
      FRONT_END_ADDRESSES_FILE,
      JSON.stringify(contractAddresses)
    );
  }
};

export default updateUI;
updateUI.tags = ['all', 'frontend'];
dibakarsutradhar commented 2 years ago

Will come back to the client issue after a while. Currently halting the client dev for couple of days.