0

I feel frustrated when I was reading the documentation of function returns. If function return multiple values. How to get the correct return from calling the function in frontend? When I see the response, it is an array like stuff, with the type that I define in side the function return.

I am using web3 & web-vitals npm package for my frontend. It will be nice if some examples can be provided. Thank you very much.

1 Answer 1

0

Treat the returned value as objects. Check this web3js code. The called contract function returns multiple data as objects.

async function getSiteStats() {
    let rawResult = await contract.methods.getSiteStats().call();
 
    let retrieved = {
        totalInvested: web3.utils.fromWei(rawResult[0]), 
        totalDeposits: parseInt(rawResult[1]),
        contractBalance: web3.utils.fromWei(rawResult[2]),
        contractPercent: (parseInt(rawResult[3]) / _PERCENTS_DIVIDER*100)
        }

    return retrieved;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.