5

I'm working on a nextjs/react project in which i want to fetch the health factor of an address on AAVE. This can be done by calling getUserAcountData(address) on the lending pool contract. I can sucessfully call it in a simple nodejs project but when i call it in my nextjs/react app it gives me an error.

Here is the code I run (on ropsten testnet). LP_ABI is simply the ABI for the AAVE Lending Pool Contract which can be found here.

All addresses are Ropsten addresses

import React, { Component } from 'react' import setupWeb3 from '../src/web3' import LP_ABI from '../abi/LendingPool.json' class Index extends Component { web3 = null getHealthFactor = async () => { let lpContract = new this.web3.eth.Contract( LP_ABI, "0x9E5C7835E4b13368fd628196C4f1c6cEc89673Fa" ) try { await lpContract.methods .getUserAccountData("0x8e5687908487cf9362632D074965Fe4B83D660a2") .call() } catch (error) { console.log('Contract', error) } } async componentDidMount() { const web3Manager = await setupWeb3() this.web3 = web3Manager.web3 } } 

the setupWeb3 function

// ´../src/web3.js´-file const Web3 = require('web3') const HDWalletProvider = require('@truffle/hdwallet-provider') async function setupWeb3() { if (typeof window !== 'undefined') { const walletProvider = new HDWalletProvider( <MNEMONIC>, <INFURA HTTP ENDPOINT> ) var web3 = new Web3(walletProvider) return { web3: web3 } } catch (error) { console.log('web3.js', error) return { web3: null } } } } export default setupWeb3 

the error

Contract Error: data out-of-bounds (length=132, offset=160, code=BUFFER_OVERRUN, version=abi/5.0.0-beta.153) at Logger.makeError (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/@ethersproject/logger/lib.esm/index.js:166) at Logger.throwError (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/@ethersproject/logger/lib.esm/index.js:175) at Reader._peekBytes (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js:112) at Reader.readBytes (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js:123) at Reader.readValue (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js:129) at NumberCoder.decode (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/@ethersproject/abi/lib.esm/coders/number.js:32) at :3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/@ethersproject/abi/lib.esm/coders/array.js:78 at Array.forEach (<anonymous>) at unpack (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/@ethersproject/abi/lib.esm/coders/array.js:56) at TupleCoder.decode (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js:22) at AbiCoder.decode (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/@ethersproject/abi/lib.esm/abi-coder.js:88) at ABICoder._N_E.push../node_modules/web3-eth-abi/src/index.js.ABICoder.decodeParameters (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/web3-eth-abi/src/index.js:347) at Contract._N_E.push../node_modules/web3-eth-contract/src/index.js.Contract._decodeMethodReturn (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/web3-eth-contract/src/index.js:572) at Method.outputFormatter (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/web3-eth-contract/src/index.js:935) at Method._N_E.push../node_modules/web3-core-method/src/index.js.Method.formatOutput (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/web3-core-method/src/index.js:169) at sendTxCallback (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/web3-core-method/src/index.js:653) at onJsonrpcResult (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/web3-core-requestmanager/src/index.js:179) at :3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/@trufflesuite/web3-provider-engine/index.js:240 at :3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/async/internal/once.js:12 at replenish (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/async/internal/eachOfLimit.js:61) at :3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/async/internal/eachOfLimit.js:71 at eachLimit (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/async/eachLimit.js:43) at :3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/async/internal/doLimit.js:9 at end (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/@trufflesuite/web3-provider-engine/index.js:217) at Object.callback (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/@trufflesuite/web3-provider-engine/subproviders/rpc.js:72) at cbOnce (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/xhr/index.js:64) at XMLHttpRequest.loadFunc (:3000/_next/static/chunks/pages/webpack:/_N_E/node_modules/xhr/index.js:131) 
16
  • Please get rid of all those sessionStorage.getItem(...) expressions, and place the actual values that they return instead. We're not supposed to guess what this function does! Commented Sep 23, 2020 at 16:39
  • Please also bother to specify what LP_ABI is, because we're not supposed to guess that either! Commented Sep 23, 2020 at 16:39
  • You may well get rid of all the frontend-related (HTML) code here, because it has absolutely no relevance to the problem that you're describing. Commented Sep 23, 2020 at 16:40
  • Note that a question here should ideally enclose ALL the relevant information and ONLY the relevant information. Commented Sep 23, 2020 at 16:41
  • I agree the front end was unnessesary, the other things i thought were pretty self-explanatory but i have updated the question as per your comments! Commented Sep 23, 2020 at 16:51

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.