Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web3.eth.Contract can't parse ABI correctly [web.1.0.0-beta.47] #2444

Closed
lebed2045 opened this issue Mar 3, 2019 · 3 comments
Closed

web3.eth.Contract can't parse ABI correctly [web.1.0.0-beta.47] #2444

lebed2045 opened this issue Mar 3, 2019 · 3 comments
Labels
Bug Addressing a bug

Comments

@lebed2045
Copy link

Simple nodejs program which calls totalSupply() from Dai smartcontract

const Web3 = require('web3');
const rpcURL = 'https://mainnet.infura.io/v3/<your_key>';
const web3 = new Web3(rpcURL);


const daiSmartcontractAddress = "0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359";
const daiSmartcontactAbi = [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"stop","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"guy","type":"address"},{"name":"wad","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"owner_","type":"address"}],"name":"setOwner","outputs":[],"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":"src","type":"address"},{"name":"dst","type":"address"},{"name":"wad","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"guy","type":"address"},{"name":"wad","type":"uint256"}],"name":"mint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"wad","type":"uint256"}],"name":"burn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"name_","type":"bytes32"}],"name":"setName","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"src","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"stopped","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"authority_","type":"address"}],"name":"setAuthority","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"guy","type":"address"},{"name":"wad","type":"uint256"}],"name":"burn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"wad","type":"uint256"}],"name":"mint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"dst","type":"address"},{"name":"wad","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"dst","type":"address"},{"name":"wad","type":"uint256"}],"name":"push","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"src","type":"address"},{"name":"dst","type":"address"},{"name":"wad","type":"uint256"}],"name":"move","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"start","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"authority","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"src","type":"address"},{"name":"guy","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"src","type":"address"},{"name":"wad","type":"uint256"}],"name":"pull","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"symbol_","type":"bytes32"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"guy","type":"address"},{"indexed":false,"name":"wad","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"guy","type":"address"},{"indexed":false,"name":"wad","type":"uint256"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"authority","type":"address"}],"name":"LogSetAuthority","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"LogSetOwner","type":"event"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"src","type":"address"},{"indexed":true,"name":"guy","type":"address"},{"indexed":false,"name":"wad","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"src","type":"address"},{"indexed":true,"name":"dst","type":"address"},{"indexed":false,"name":"wad","type":"uint256"}],"name":"Transfer","type":"event"}];


const contract = new web3.eth.Contract(daiSmartcontactAbi, daiSmartcontractAddress);


contract.methods.totalSupply().call((err, result) => { console.log(result) });

Expected behavior

npm install --save web3@1.0.0-beta.34
node app.js
89646984224589023839810726

Actual behavior

npm install --save web3@1.0.0-beta.46
node app.js
(node:91820) UnhandledPromiseRejectionWarning: Error: Returned values aren't valid, did it run Out of Gas?
    at AbiCoder.decodeParameters (/Users/<username>/programming/learning_blockchain/web3_basic/node_modules/web3/node_modules/web3-eth-abi/dist/web3-eth-abi.cjs.js:116:15)
    at CallContractMethod.afterExecution (/Users/<username>/programming/learning_blockchain/web3_basic/node_modules/web3/node_modules/web3-eth-contract/dist/web3-eth-contract.cjs.js:720:34)
    at CallContractMethod._callee$ (/Users/<username>/programming/learning_blockchain/web3_basic/node_modules/web3/node_modules/web3-core-method/dist/web3-core-method.cjs.js:457:39)
    at tryCatch (/Users/<username>/programming/learning_blockchain/web3_basic/node_modules/regenerator-runtime/runtime.js:62:40)
    at Generator.invoke [as _invoke] (/Users/<username>/programming/learning_blockchain/web3_basic/node_modules/regenerator-runtime/runtime.js:288:22)
    at Generator.prototype.(anonymous function) [as next] (/Users/<username>/programming/learning_blockchain/web3_basic/node_modules/regenerator-runtime/runtime.js:114:21)
    at asyncGeneratorStep (/Users/<username>/programming/learning_blockchain/web3_basic/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
    at _next (/Users/<username>/programming/learning_blockchain/web3_basic/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:182:7)
(node:91820) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:91820) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Steps to reproduce the behavior

see above

Error Logs

see above

Versions

[NPM 6.1.0, Node v9.11.1, web3@1.0.0-beta.46 , OS HightSierra 10.13.6, Macbook pro 13' late 2012]

@nivida
Copy link
Contributor

nivida commented Mar 3, 2019

Thanks for creating this issue! I will check and fix it asap.

@nivida nivida added the Bug Addressing a bug label Mar 3, 2019
@chaitanyapotti
Copy link
Contributor

Also occurs in beta.47

Although the message is

Error: Invalid bytes string given: 0x
 at AbiCoder.decodeParameters (C:\Users\Naina\source\repos\Learning-solidity\kickstart\node_modules\web3-eth-abi\dist\web3-eth-abi.cjs.js:64:15)

@nivida
Copy link
Contributor

nivida commented Mar 5, 2019

I've tested it with a standard ERC20 token and couldn't reproduce your issue. Could you create an example repository/branch or gist file which contains everything for testing it closer?

@nivida nivida added more information needed and removed Bug Addressing a bug labels Mar 5, 2019
@nivida nivida added Bug Addressing a bug and removed more information needed labels Mar 29, 2019
@nivida nivida closed this as completed Mar 29, 2019
@nivida nivida mentioned this issue Apr 4, 2019
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
None yet
Development

No branches or pull requests

3 participants