Open lebed2045 opened 5 years ago
Same problem here. I am using web3 version 1.0.0-beta.48 and node.js version v10.11.0 on windows 10.
I found a solution by chaining the .then(onSuccess, onFailure), like this:
contract.methods.totalSupply().call() .then( (res)=>{ console.log(res) }, (error)=>{ console.log(error) } )
@jmlon i am still getting Error: Invalid bytes string given: 0x . Have you done any other changes also?
@jmlon i am still getting Error: Invalid bytes string given: 0x . Have you done any other changes also?
Yes, when converting the private key into a buffer, I had to trim off the '0x' from the start of the string.
@jmlon i am still getting Error: Invalid bytes string given: 0x . Have you done any other changes also?
Yes, when converting the private key into a buffer, I had to trim off the '0x' from the start of the string.
Yes ,but it only required for sending sign Transaction. I am getting this error on calling any method on smartContract Eg: contract.methods.balanceOf(account1)
.
Please ignore the Promise returned I have Handled that part.
I even tried using JSON_RPC eth_call to get result but i received {"jsonrpc":"2.0","id":1,"result":"0x"} as a response.
@jmlon i am still getting Error: Invalid bytes string given: 0x . Have you done any other changes also?
Yes, when converting the private key into a buffer, I had to trim off the '0x' from the start of the string.
Yes ,but it only required for sending sign Transaction. I am getting this error on calling any method on smartContract Eg:
contract.methods.balanceOf(account1)
. Please ignore the Promise returned I have Handled that part.I even tried using JSON_RPC eth_call to get result but i received {"jsonrpc":"2.0","id":1,"result":"0x"} as a response.
I don't remember any other problems with this example. Here is the example with the corrections that worked for me
`const Web3 = require('web3')
const infura = "https://mainnet.infura.io/
const contract = new web3.eth.Contract(omgABI, omgAddress)
contract.methods.name().call().then( res=>console.log(res), err=>console.log(err) ) contract.methods.symbol().call().then( res=>console.log(res), err=>console.log(err) ) contract.methods.totalSupply().call().then( res=>console.log(res), err=>console.log(err) ) contract.methods.mintingFinished().call().then( res=>console.log(res), err=>console.log(err) ) contract.methods.balanceOf("0x417e631d2934704a73b8ff6f0adf16d9dbaff2a7").call().then( res=>console.log(res), err=>console.log(err) ) `
I am getting this error after calling the totalSupply function