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