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

90
Views
Obtener el valor de retorno del contrato inteligente en JS

Estoy tratando de llamar a un método desde un contrato inteligente y no entiendo la respuesta que recibo. Estoy ejecutando el siguiente contrato inteligente en una cadena de bloques local usando ganache-cli. Luego estoy tratando de llamar al método testFunc desde el siguiente código javascript. Obtengo un objeto como respuesta que no parece tener el valor de retorno del método, pero tiene detalles del método.

Contrato inteligente:

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

Código JavaScript:

 <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>

El objeto de respuesta que obtengo se ve así: [![ingrese la descripción de la imagen aquí][1]][1]

¿Es esta la respuesta que se supone que debo obtener y, de ser así, cómo analizo esto para obtener el valor de retorno del método?
[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!