DEX Problem using react/1inch api?

Hi coders,

I know that moralis has stopped using the dex function on their boilerplate but im still interested. but getting a error 400 trying to get a quote

My Code :

const useInchDex = (chain) =>  {
const { account,  chainId, active } = useWeb3React();
 const [tokenList, setTokenlist] = useState();

const  web3 = new Web3(window.ethereum);

   

   **useEffect((chain) => {**

**      if (!account&& !active) return null;**

**  **
**      listAvailableTokens();   **

** })**

**  }, [account, chain, active]);**

// useEffect - to load the list from function below.

//const chain = {

  //'bsc' : responseTwo,

  //'eth': responseOne,

//}

    async function listAvailableTokens() {

      const ethList = "https://api.1inch.exchange/v4.0/1/tokens";

const bscList =   "https://api.1inch.exchange/v4.0/56/tokens";

const polyList =   "https://api.1inch.exchange/v4.0/137/tokens";

const testList = "https://api-polygon-tokens.polygon.technology/tokenlists/testnet.tokenlist.json";


const requestOne = axios.get(ethList);

const requestTwo = axios.get(bscList);

 const requestThree = axios.get(polyList)

  await axios.all([requestOne, requestTwo,requestThree]).then(axios.spread((...responses) => {

    const responseOne = responses[0]

    const responseTwo = responses[1]

    const responseThree = responses[2]

   

    console.log(responseOne.data.tokens,responseTwo.data.tokens)

    

      //);

    //}

    if (chain == 0x1 ){

     setTokenlist(

responseOne.data.tokens,// responseTwo.data.tokens

    // responseTwo.data.tokens

          

    );

    }

   

   if (chain == 0x38 ){

      setTokenlist(

//responseTwo.data.tokens,// responseTwo.data.tokens

    responseTwo.data.tokens

          

    );

    }

     

    if (chain == 0x89 ){

      setTokenlist(

responseThree.data.tokens,// responseTwo.data.tokens

    // responseTwo.data.tokens

          

     );

    }

   

    // use/access the results

  })).catch(errors => {

    // react on errors.

  })

         

      //let tokens = result.tokens;

     // console.log(tokens);

       

      // setTokenlist(tokens);

       //setTokenlist(tokens);

         //for (const address in tokens){

                // let token = tokens;

     // tokenList([tokens]);

        //}

   

         //}

    //  }catch(error){

      //  console.log(error);

      //}

     

};


 /*-------------------   ----------------- ------------------------------------------------------------*/


    const walletAddress = account;

    //const apiBaseUrl = 'https://api.1inch.io/v4.0/' + chainId;



   //function apiRequestUrl(quote, getQuote) {

     // return apiBaseUrl + quote + '?' + (new URLSearchParams(getQuote)).toString();

     

  //}  

// console.log('quote:',apiRequestUrl)

    //  const getQuote = async (params) => ({

      //  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:  Web3.utils.toWei(

 //new BN( params.fromAmount),

  // params.fromToken.decimals,

 // 'ether'

//).toString(),  

 // }

 

  //)

        // params.fromToken.decimals,

 // const getQuote before

      

     // tokenList[tokens].address

     const apiBaseUrl = 'https://api.1inch.io/v4.0/' + chainId;

// --- comps from 1inch

function apiRequestUrl(methodname, queryParams) {

       return apiBaseUrl + methodname + '?' + (new URLSearchParams(queryParams)).toString();

         

  }

  const broadcastApiUrl = 'https://tx-gateway.1inch.io/v1.1/' + chainId + '/broadcast';

  async function broadCastRawTransaction(rawTransaction) {

    return fetch(broadcastApiUrl, {

        method: 'post',

        body: JSON.stringify({rawTransaction}),

        headers: {'Content-Type': 'application/json'}

    })

        .then(res => res.json())

        .then(res => {

            return res.transactionHash;

        });

}

/*

async function buildTxForApproveTradeWithRouter(tokenAddress, amount) {

  const url = apiRequestUrl(

      '/approve/transaction',

      amount ? {tokenAddress, amount} : {tokenAddress}

  );

  const transaction = await fetch(url).then(res => res.json());

  const gasLimit = await web3Broard.eth.estimateGas({

      ...transaction,

      from: walletAddress

  });

  return {

      ...transaction,

  gasLimit

  };

}

async function signAndSendTransaction(transaction) {

    const {rawTransaction} = await  web3Broard.eth.accounts.signTransaction(transaction,walletAddress);

    return await broadCastRawTransaction(rawTransaction);

}

*/

 

async function buildTxForSwap(swapParams) {

  const url = apiRequestUrl('/swap', swapParams);

  return fetch(url).then(res => res.json()).then(res => res.tx);

}

async function getQuotef( params) {

 

 const qp =  {

    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:  Web3.utils.toWei(

new BN(params?.fromAmount,

//params.fromToken.decimals,

'ether'

  )).toString()  ,

 // amount: ethers.utils.parseEther(params?.fromAmount.toString()).toString(), //8 for decimals //formatether works

   fee: 1

   

}

  const url = apiRequestUrl ('/quote', qp);

 

 //return await fetch(url).then( res =>  res.json());

 const response = await fetch (url);

 const  quoteJson = await response.json();

  

console.log("quotef", quoteJson);

 //.then(res => { return  res.toTokenAmount});

 //return fetch(url).then(res => res.data).

};

getQuotef();

 





 
  }];




  }

 

}



return { getQuotef,tokenList };

  }

export default useInchDex;

I keep getting this error when trying to get a quote :
{statusCode: 400, error: ‘Bad Request’, description: ‘undefined is wrong address’, meta: Array(1), requestId: ‘571b4e69-478d-4353-8aa4-8c52001a9ff4’}
description
:
“undefined is wrong address”
error
:
“Bad Request”
meta
:
[{…}]
requestId
:
“571b4e69-478d-4353-8aa4-8c52001a9ff4”
statusCode
:
400
[[Prototype]]
:
Object

Thanks for your help , this is also connected to the InchDex component. (https://github.com/ethereum-boilerplate/ethereum-nextjs-boilerplate/blob/cee918d68651e9396c4d3dda0c4cd6b754674d26/src/components/InchDex/InchDex.jsx)

What is your package.json? That error is coming from this function?

async function getQuotef( params) {

  "name": "my-webpack-project",

  "version": "1.0.0",

  "private": true,

  "dependencies": {

    "@coinbase/wallet-sdk": "^3.3.0",

    "@ethereum-waffle/ens": "^3.4.4",

    "@metamask/providers": "^9.0.0",

    "@moralisweb3/core": "^2.7.0",

    "@moralisweb3/evm-utils": "^2.7.0",

    "@nomiclabs/hardhat-ethers": "^2.1.1",

    "@nomiclabs/hardhat-waffle": "^2.0.3",

    "@openzeppelin/contracts": "^4.7.3",

    "@testing-library/jest-dom": "^5.16.2",

    "@testing-library/react": "^12.1.2",

    "@testing-library/user-event": "^13.5.0",

    "@types/web3": "^1.2.2",

    "@web3-react/coinbase-wallet": "^8.0.22-beta.0",

    "@web3-react/core": "^6.1.9",

    "@web3-react/fortmatic-connector": "^6.1.6",

    "@web3-react/injected-connector": "^6.0.7",

    "@web3-react/portis-connector": "^6.2.11",

    "@web3-react/walletconnect": "^8.0.35-beta.0",

    "@web3-react/walletconnect-connector": "^6.2.13",

    "@web3-react/walletlink-connector": "^6.2.14",

    "antd": "^4.18.6",

    "assert": "^2.0.0",

    "bn.js": "^5.2.1",

    "body-parser": "^1.19.2",

    "browserslist": "^4.21.4",

    "buffer": "^6.0.3",

    "crypto-browserify": "^3.12.0",

    "dotenv": "^16.0.2",

    "ethers": "^5.7.2",

    "fetch": "^1.1.0",

    "hardhat": "^2.12.0",

    "http": "^0.0.1-security",

    "https-browserify": "^1.0.0",

    "mime": "^3.0.0",

    "os-browserify": "^0.3.0",

    "patch-package": "^6.4.7",

    "process": "^0.11.10",

    "react": "^17.0.2",

    "react-blockies": "^1.4.1",

    "react-dev-utils": "^12.0.0",

    "react-dom": "^17.0.2",

    "react-moralis": "^1.3.5",

    "react-router-dom": "^6.2.1",

    "react-scripts": "^5.0.0",

    "rollup-plugin-node-builtins": "^2.1.2",

    "solc": "^0.8.17",

    "stream": "^0.0.2",

    "stream-browserify": "^3.0.0",

    "url": "^0.11.0",

    "util": "^0.12.4",

    "web-vitals": "^2.1.4",

    "web3-utils": "^1.7.3",

    "web3modal": "^1.9.8",

    "yesno": "^0.3.1",

    "yesno-dialog": "^0.2.1"

  },

  "scripts": {

    "start": "react-scripts start",

    "build": "webpack --mode=production --node-env=production",

    "test": "react-scripts test",

    "eject": "react-scripts eject",

    "build:dev": "webpack --mode=development",

    "build:prod": "webpack --mode=production --node-env=production",

    "watch": "webpack --watch",

    "serve": "webpack serve"

  },

  "eslintConfig": {

    "extends": [

      "react-app",

      "react-app/jest"

    ]

  },

  "browserslist": {

    "production": [

      ">0.2%",

      "not dead",

      "not op_mini all"

    ],

    "development": [

      "last 1 chrome version",

      "last 1 firefox version",

      "last 1 safari version"

    ]

  },

  "devDependencies": {

    "@babel/plugin-syntax-top-level-await": "^7.14.5",

    "@types/node": "^17.0.19",

    "@webpack-cli/generators": "^2.5.0",

    "node-polyfill-webpack-plugin": "^1.1.4",

    "react-app-rewired": "^2.2.1",

    "stream-http": "^3.2.0",

    "webpack": "^5.69.1",

    "webpack-cli": "^4.10.0",

    "webpack-dev-server": "^4.7.4"

  },

  "description": "My webpack project"

}

This looks like a custom project, not the boilerplate. E.g. that has react-moralis but no moralis or moralis-v1 and it’s using newer 2.0 only packages (like @moralisweb3/core). Can you give more info?

Try hardcoding the addresses first to see where the problem is with the quote function - this error doesn’t seem related to the use of Moralis.