edit) VM execution error was a bug on Web3, confirmed my code works fine.
I am trying to fetch random addresses from blockchain and trying to categorize them if it is an ERC20 contract address or not.
I've tried with web3.eth.call to check if the contract has a method totalSupply() but there was no success on that thing, with the single address it works fine however at the production stage it returns an odd (node:10722) UnhandledPromiseRejectionWarning: Error: Returned error: VM execution error.
Referring related documents or codes wouldn't help with me unless with web3 1.0.
Here is my code that doesn't work
var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("http://127.0.0.1:8545"));
var ABI = [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}];
var myContract = new web3.eth.Contract(ABI, "0x085b0fdf115aa9e16ae1bddd396ce1f993c52220");
async function checkAddress() {
var call = await web3.eth.call({ to: "0x085fb4f24031eaedbc2b611aa528f22343eb52db", data:web3.utils.sha3("totalSupply()")});
if (call != '0x') {
console.log('ERC20 token detected');
} else {
console.log('Not an ERC20 token address');
}
}
checkAddress();
with the single address it works fine- what does that suppose to mean? – goodvibration Mar 20 '19 at 13:50totalSupplyis an ERC20 contract. – goodvibration Mar 20 '19 at 13:51totalsupplyis needed, – BT Enterprise Mar 20 '19 at 13:54multiple address querycode then? If that is where the problem is, then we need to see it, don't you think? Also, be advised that you are callingcheckAddresswithoutawaiting for it to complete. It will work fine as long as you don't do anything else after that (which depends on this function-call). But if you do several things (for example, calling it multiple times), then you may possibly need toawaitfor each function call to complete. Without seeing your code, it would be difficult to know for sure. – goodvibration Mar 20 '19 at 14:12