1

I try to fetch the current offer price for my NFT project but i currently get undefined in this function

    useEffect(() => {
        returnsCurrentOfferPrice(NFT.tokenId)
          .then((offer) => {
            console.log(offer);
            setReturnCurrentOfferPrice(offer);
          })
          .catch((error) => {
            console.log('Current offer price error', error);
          });
    }, [NFT.tokenId]);

This is my use State Snippet

const [returnCurrentOfferPrice, setReturnCurrentOfferPrice] = useState(null);

This is how i retrieve the function into my UI

    const returnsCurrentOfferPrice = async (tokenId) => {
        await getCurrentOfferPrice(tokenId)
    }

And finally this is how i retrieve the data from the blockchain

    const getCurrentOfferPrice = async (tokenId) => {
        const web3Modal = new Web3Modal();
        const connection = await web3Modal.connect();
        const provider = new ethers.providers.Web3Provider(connection);
        const contract = signerOrProvider(provider);
        const currentOfferPrice = await contract.getCurrentOfferAmount(tokenId);
        const bigNumber = ethers.BigNumber.from(currentOfferPrice);
        const currentOfferPriceInEther = ethers.utils.formatEther(bigNumber)
        console.log('Current offer price', currentOfferPriceInEther );
        return currentOfferPriceInEther;
    }
Oliver
  • 11
  • 2

0 Answers0