Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

84
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda