CRYPTO NEWS

TypeError: Cannot read properties of undefined (reading ‘toNumber’), When trying to fetch totalSupply

I’m trying to fetch totalSupply from my smart contract using react-moralis useWeb3ExecuteFunction and got this problem enter image description here

the code

import Head from 'next/head' 

import styles from ‘../styles/Home.module.css’ import { useMoralis, useWeb3ExecuteFunction } from ‘react-moralis’; import Web3Modal from "web3modal"; import {ethers, BigNumber} from ‘ethers’; import { useState, useCallback, useEffect } from ‘react’; import abi from ‘./ABI.json’; import { CoinbaseWalletSDK} from ‘@coinbase/wallet-sdk’;

const providerOptions = { } const address = "0x92BcA0381D537942B427F785bA1FDFF8321B9e5d";

export default function Home() { const {isWeb3Enabled} = useMoralis(); const [web3Provider, setWeb3Provider] = useState(null); const [mintAmount, setMintAmount] = useState(1); const maxMintAmountPerTx = 5; const cost = 0.001; const [totalSupply, setTotalSupply] = useState(0);

const { fetch: getTotalSupply } = useWeb3ExecuteFunction({ abi: abi, contractAddress: address, functionName: ‘totalSupply’, });

const updateUiValues = useCallback(async () => { const totalSupplyFromCall = (await getTotalSupply()); setTotalSupply(totalSupplyFromCall.toNumber()); }, [getTotalSupply]);

useEffect(() => { if (web3Provider) { updateUiValues();

  // cleanup   return () => {     setTotalSupply(0);   }; } 

}, [web3Provider, updateUiValues]);

function handleDecrement() { setMintAmount(Math.max(1, mintAmount – 1)); }

function handleIncrement() { setMintAmount(Math.min(maxMintAmountPerTx, mintAmount + 1)); }

async function handleMint() { if (web3Provider) { let totalCost = String(cost * mintAmount); const web3Modal = new Web3Modal({ cacheProvider: true, // optional providerOptions // required }); const instance = await web3Modal.connect(); const provider = new ethers.providers.Web3Provider(instance); const signer = provider.getSigner(); const contract = new ethers.Contract( address, abi, signer ); try { const response = await contract.mint(BigNumber.from(mintAmount),{value:ethers.utils.parseUnits(totalCost)}); console.log(‘response: ‘, response) } catch (err) { console.log("error: ", err) } } }

async function connect () { try { let web3Modal = new Web3Modal ({ cacheProvider: true, providerOptions, }); const web3ModalInstance = await web3Modal.connect(); const web3ModalProvider = new ethers.providers.Web3Provider(web3ModalInstance) console.log(web3ModalProvider) if(web3ModalProvider){ setWeb3Provider(web3ModalProvider); } } catch(err) {

} 

}

WIN NFT HERO Offers Players An Excellent Game Experience With Rewards

WIN NFT HERO, a blockchain game based on the TRON network, is leading the GameFi space with its excellent P2E gaming experience. WIN NFT HERO is the next-gen GameFi and NFT turn-based strategy game that allows gamers to fully own their game assets, such as heroes, NFT assets, or equipment. The hero NFTs are meticulously::Listen

WIN NFT HERO Offers Players An Excellent Game Experience With Rewards

WIN NFT HERO, a blockchain game based on the TRON network, is leading the GameFi space with its excellent P2E gaming experience.

WIN NFT HERO is the next-gen GameFi and NFT turn-based strategy game that allows gamers to fully own their game assets, such as heroes, NFT assets, or equipment. The hero NFTs are meticulously and delicately created and consist of five elements: class, skill, attributes, bond, and quality. Each hero has their position, with long-range attackers and short-range tanks essential in winning combats. 

For better results, the game allows players to create strategic plans in advance, such as arranging their positions, selecting different heroes, choosing the appropriate equipment, or bonding with other heroes in the squad. Note heroes of the same class or gene can be combined to form bonds that boost players’ performance in combat. 

WIN NFT HERO has multiple game modes, including ALLSTAR, Adventure, Mission, and Dungeon. Each more offers different rewards. Note in a specific mode; players can experience all heroes and build their formation. The game plans to introduce more game modes as the metaverse grows.

Notably, the game is committed to building a TRON metaverse that combines free play ad play with ECO. By doing so, the team behind the project seeks to allow users to win various in-game assets for free while at the same time offering them a marketplace to trade the assets. The platform offers high performance and low gas fees allowing players to trade freely on the WIN NFT HERO official marketplace. Players can get rare materials to form the game by staking to Dungeon and get income for their activities. 

Currently, WIN NFT HERO is undertaking a second round of closed beta tests alongside three events offering participants numerous rewards. The three events are aimed at helping players challenge WIN NFT HERO. For the first event, participants will be required to find any bugs in the game. The second event requires players to experience the new All-Star game play and layout of their All-Star lineup. The last event requires users to participate in the testing of the new strategy All Star gameplay to become the strongest king. In addition, the team is planning to release more rewards for early investors as the game progresses to a new milestone. 

TypeError: Cannot read properties of undefined (reading ‘toNumber’), When trying to fetch totalSupply

Shopping cart
There are no products in the cart!
Continue shopping
0