New web3.eth.Contract cause error

Hi, I have this code:

myW3.test = async (account) => {
  var web3 = await Moralis.Web3.enable();
  var PANCAKE_V2_ROUTER_ADDR = '0x10ED43C718714eb63d5aA57B78B54704E256024E';
  var ROUTER_ABI = ['function getAmountsOut(uint amountIn,address[] memory path) public view returns (uint[] memory amounts)',
    'function swapExactTokensForTokens(uint amountIn,uint amountOutMin,address[] calldata path,address to,uint deadline) external returns (uint[] memory amounts)',
    'function swapExactTokensForTokensSupportingFeeOnTransferTokens(uint amountIn,uint amountOutMin,address[] calldata path,address to,uint deadline) external'
];

  // the line bellow throws error...
  var ROUTER_CONTRACT =  new web3.eth.Contract(ROUTER_ABI, PANCAKE_V2_ROUTER_ADDR);
};

I am using react-moralis; While calling this function on a button Click, I ve got this Error on browser:

Unhandled Rejection (TypeError): Cannot create property ‘constant’ on string ‘function getAmountsOut(uint amountIn,address[] memory path) public view returns (uint[] memory amounts)’

Where did I made it wrong?

1 Like

Hi @tungtien

Try to change the ABI code. Take it from bscscan

Let me know if it worked out for you. :slight_smile:

1 Like

Thanks @Yomoo, It works.
The errors cause from reusing ABI format which I used for Ethers.js.;
ethers.js accept ABI as an array of strings describing functions that I want to use; While web3.js reads full ABI as it is…

1 Like

This is a good distinction that you pointed out which others might find useful. Thank you! :raised_hands:

2 Likes