React useOneInchQuote not returning the Quote

so the last topic I made was the fact oneInchSwap/Quote wasn’t working turns out it was my error because I didn’t have the OneInch Plugin installed.

It seems now that it is trying to work but my code is bad and isn’t retrieving the quote data, please excuse me i just started learning to code in JS like 4 months ago and am just trying to learn and correct my errors.

this is what the terminal returns

here is my code

import styles from '../styles/Swap.module.css';
import { useOneInchQuote } from 'react-moralis';

//test


export default function Swap(props) {
  
  const userContract = props.input
  const chain = 'bsc'
  const wbnb = '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'

  function Quote() {
    const { getQuote, data, isFetching, isLoading, error } = useOneInchQuote({
      chain: chain, 
      fromTokenAddress: wbnb,
      toTokenAddress: userContract, 
      amount: 1000,
    });
     

  }
  

  return(

      <div 
        className={ styles.SwapWrapper}
      >

        <div className={ styles.TopScreen }>
            <button onClick={() => console.log(Quote)}></button>
        </div>

        <p className={ styles.ContractDisplay }>{props.userContract}</p>

        <input 
          onBlur={(e) => props.setAmmount(e.target.value) | Number }
          className={ styles.Ammount }
        >
        </input>

        <button className={ styles.Buy }>
          BUY
        </button>
        <button className={ styles.Sell }>
          SELL
        </button>

      </div>
  );
} 

I know that I’m calling for the log of the function itself but if i remove the function the useOneInchQuote just throws an error.

Cannot read properties of undefined (reading ‘address’)

is there any way at all on how to get this working there is like 0 documentation on this other that the provided code:

import { useOneInchQuote } from "react-moralis";

function Quote() {
  const { getQuote, data, isFetching, isLoading, error } = useOneInchQuote({
    chain: 'bsc', // The blockchain you want to use (eth/bsc/polygon)
    fromTokenAddress: '0x0da6ed8b13214ff28e9ca979dd37439e8a88f6c4', // The token you want to swap
    toTokenAddress: '0x6fd7c98458a943f469e1cf4ea85b173f5cd342f4', // The token you want to receive
    amount: 1000,
  });
  return (
     <div>
        {error && <>{JSON.stringify(error)}</>}
        <pre>{JSON.stringify(data, null, 2)}</pre>
    </div>
  );
}

Any ideas at all would help! Thank you

I think that data will contains the info after getQuote is executed

one second let me change some things and ill report back lol, i apologize for my ignorance.

I don’t get it man i’m able to get user balances using { useMoralis } and some other stuff but as far as anything else plugin wise ‘react-moralis’ such as the oneInch functionality there is nearly zero meaningful documentation on how to actually use it or it simply doesn’t work.

Do you know anyone at Moralis that knows how to use react and can give a quick example of this working on their end?

sorry im just getting frustrated i have been trying to get this to work for days… a simple quote

According to the funcitoning react boilerplate, this is how it is fetched -

const { Moralis, account } = useMoralis();

const getQuote = async (params) =>
    await Moralis.Plugins.oneInch.quote({
      chain: params.chain, // The blockchain  you want to use (eth/bsc/polygon)
      fromTokenAddress: params.fromToken.address, // The token you want to swap
      toTokenAddress: params.toToken.address, // The token you want to receive
      amount: Moralis.Units.Token(
        params.fromAmount,
        params.fromToken.decimals,
      ).toString(),
    });
1 Like

sir i want to give you a kiss lmao brb lemme test

can you link the boilerplate?

Here you go -