This is my smart contract written in solidity (v.0.5.16) -
pragma solidity ^0.5.0; contract MyContract { function myFunction() public pure returns(uint256 myNumber, string memory myString) { return (23456, "Hello!%"); } } This is my web3 (v.1.2.6) code written in NodeJS (v.10.16.1) -
const Web3 = require('web3'); const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:7545')); const abi = [{"constant":true,"inputs":[],"name":"myFunction","outputs":[{"internalType":"uint256","name":"myNumber","type":"uint256"},{"internalType":"string","name":"myString","type":"string"}],"payable":false,"stateMutability":"pure","type":"function"}]; const address = '0x692a70d2e424a56d2c6c27aa97d1a86395877b3a'; const default_address = '0x597c0d6383aAEad3895Ee8191F4eF2Dd8940B6E7'; const myContract = new web3.eth.Contract(abi, address); myContract.deploy({ data: '0x608060405234801561001057600080fd5b5061012f806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063c3780a3a14602d575b600080fd5b603360b2565b6040518083815260200180602001828103825283818151815260200191508051906020019080838360005b838110156077578082015181840152602081019050605e565b50505050905090810190601f16801560a35780820380516001836020036101000a031916815260200191505b50935050505060405180910390f35b60006060615ba08090506040518060400160405280600781526020017f48656c6c6f21250000000000000000000000000000000000000000000000000081525091509150909156fea265627a7a723158207c74308dd7b2369a27728a1c18b137dbf8de6f83a3015e84d898f4312374719764736f6c63430005100032' }) .send({ from: default_address, gas: 1500000, gasPrice: '30000000000000' }).then(function(newContractInstance){ console.log("contract address -"); console.log(newContractInstance.options.address); // instance with the new contract address }); myContract.methods.myFunction().call() .then(function(result){ console.log(result); }) .catch(function(error){ console.log(error); }); It prints the value of newContractInstance.options.address but gives this ERROR on call() -
Error: Returned values aren't valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced. at ABICoder.decodeParameters (...\node_modules\web3-eth-abi\src\index.js:239:15) at Contract._decodeMethodReturn (...\node_modules\web3-eth-contract\src\index.js:557:22) at Method.outputFormatter (...\node_modules\web3-eth-contract\src\index.js:910:46) at Method.formatOutput (...\node_modules\web3-core-method\src\index.js:167:54) at sendTxCallback (...\node_modules\web3-core-method\src\index.js:596:33) at ...\node_modules\web3-core-requestmanager\src\index.js:147:9 at XMLHttpRequest.request.onreadystatechange (...\node_modules\web3-providers-http\src\index.js:110:13) at XMLHttpRequestEventTarget.dispatchEvent (...\node_modules\xhr2-cookies\dist\xml-http-request-event-target.js:34:22) at XMLHttpRequest._setReadyState (...\node_modules\xhr2-cookies\dist\xml-http-request.js:208:14) at XMLHttpRequest._onHttpResponseEnd (...\node_modules\xhr2-cookies\dist\xml-http-request.js:318:14) at IncomingMessage.<anonymous> (...\node_modules\xhr2-cookies\dist\xml-http-request.js:289:61) at IncomingMessage.emit (events.js:203:15) at endReadableNT (_stream_readable.js:1145:12) at process._tickCallback (internal/process/next_tick.js:63:19)
myContract.methods.myFunctioninsidefunction(newContractInstance). Otherwise, you are doing it without waiting for the contract deployment to complete.