Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

83
Views
Getting return value of smart contract in JS

I am trying to call a method from a smart contract and I don't understand the response I am getting. I am running the following smart contract on a local blockchain using ganache-cli. I am then trying to call the testFunc method from the below javascript code. I am getting an object as a response that doesn't seem to have the return value of the method in it but does have details of the method.

Smart contract:

pragma solidity ^0.8.3;

contract HelloWorld {
    function testFunc() pure public returns (string memory){
        return "Hello World!";
    }
}

Javascript code:

<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script>
    const web3 = new Web3("http://localhost:8545");
    const contractAddress = "0x4E265652f963548b8A8e6452575B3009538b858f";
    const abiArray = [{"inputs":[],"name":"testFunc","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"}];
    var contract = new web3.eth.Contract(abiArray, contractAddress);
    
    console.log(contract.methods.testFunc.call()); //I have also tried contract.methods.testFunc() which produced the same result
</script>

The response object I am getting looks like this: [![enter image description here][1]][1]

Is this the response I am supposed to get and if so how do I parse this to get the return value of the method?
[1]: https://i.stack.imgur.com/NIkpL.png

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!