Created
February 26, 2020 21:38
-
-
Save surhud004/59f876f6f991941e2145e9cbca2f6134 to your computer and use it in GitHub Desktop.
web3 - Error while calling pure function via web3 using nodejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
myContract.deploy({ | |
data: '0x6080604052600060015534801561001557600080fd5b50610425806100256000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80632fe792491461004657806336328e9e146101385780634395351914610206575b600080fd5b6100bd6004803603602081101561005c57600080fd5b810190808035906020019064010000000081111561007957600080fd5b82018360208201111561008b57600080fd5b803590602001918460018302840111640100000000831117156100ad57600080fd5b9091929391929390505050610224565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100fd5780820151818401526020810190506100e2565b50505050905090810190601f16801561012a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102046004803603604081101561014e57600080fd5b810190808035906020019064010000000081111561016b57600080fd5b82018360208201111561017d57600080fd5b8035906020019184600183028401116401000000008311171561019f57600080fd5b9091929391929390803590602001906401000000008111156101c057600080fd5b8201836020820111156101d257600080fd5b803590602001918460018302840111640100000000831117156101f457600080fd5b90919293919293905050506102ee565b005b61020e610333565b6040518082815260200191505060405180910390f35b60606002838360405180838380828437808301925050509250505090815260200160405180910390208054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102e15780601f106102b6576101008083540402835291602001916102e1565b820191906000526020600020905b8154815290600101906020018083116102c457829003601f168201915b5050505050905092915050565b6102f6610339565b8181600286866040518083838082843780830192505050925050509081526020016040518091039020919061032c92919061034b565b5050505050565b60015481565b60018060008282540192505081905550565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061038c57803560ff19168380011785556103ba565b828001600101855582156103ba579182015b828111156103b957823582559160200191906001019061039e565b5b5090506103c791906103cb565b5090565b6103ed91905b808211156103e95760008160009055506001016103d1565b5090565b9056fea265627a7a72315820bfbc0b9e0b0b129ac861de9b4f3cf13d279b70eed0d44f471707326e7693dca964736f6c63430005100032' | |
}) | |
.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 | |
newContractInstance.methods.myFunction().call() | |
.then(function(result){ | |
console.log(result); | |
}) | |
.catch(console.log); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract address - | |
0xf6AEeca4d6Cc9E348dBd8cD56442764ecf6caf09 | |
Error: Returned error: VM Exception while processing transaction: revert | |
at Object.ErrorResponse (...\node_modules\web3-core-helpers\src\errors.js:29:16) | |
at ...\node_modules\web3-core-requestmanager\src\index.js:140:36 | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check the bytecode. It is different for every EVM compiler version change. Thus, gives VM Exception error.