1

I'm quite stuck with this issue. It seems like it must work, but it doesn't :D

Have a contract on rinkeby network which is working perfectly through remix(load by address) and truffle console. However method calls through web3 client refuse to work.

init:

import Web3 from 'web3';


// @ts-ignore
const web3 = new Web3(window.web3.currentProvider);

***got address & abi***

export default new web3.eth.Contract(abi, address);

usage example:

console.log(registryContract.options.address);
console.log(registryContract.methods);
const owner = await registryContract.methods.owner().call();

In console.log() i can see the actual contract address and methods. Metamask is active and web3.eth.defaultAccount shows me my correct account at rinkeby network => provider must be working.

calling the owner from remix working. with web3 i'm getting an empty array as response. Same for other methods calls.

What is possible going wrong? "web3": "^1.0.0-beta.37"

1
  • is there any solution you got ? Mar 2, 2021 at 17:03

6 Answers 6

3

The problem was with contract abi - don't know what exactly was wrong with it. I simply used abi from different source and it helped. Any tool for abi verification?

1
  • What do you mean exactly with "direct source"?
    – User
    Nov 15, 2020 at 15:03
1

I had exactly the same issue and managed to solve it by passing correct ABI object. Looks like earlier versions of solc returned ABI as a JSON string and current version returns actual JavaScript object (but I'm not sure). So you can't just print contract's ABI and paste it to web3 instance (as I did). I had to JSON.stringify returned object first and then JSON.parse copy/pasted string to the web3 instance.

0

You have some stray brackets after the method name.

Instead of

registryContract.methods.owner().call();

try

registryContract.methods.owner.call();
1
  • tried using it without () returns me methods.owner object Dec 31, 2018 at 12:06
0

Try this.

registryContract.owner(function (error, result) {
if (!error)
  console.log(result);
else
  console.error(error);
});
1
  • tried, doesn't throw any error Dec 31, 2018 at 12:08
0

Encountered exactly the same problem (all methods returning empty arrays) and was driving me mad.

The solution (the one I found anyway) was to stringify the abi resulting from the solc compiler (as mentioned earlier in this thread).

console.log(JSON.stringify(abi)); // AND NOT console.log(abi)

And to copy&paste the resulting string copy&pasted to specify the deployed contract's abi.

And pending question, any way to check that a the proxy obtained on a deployed contract using its address and associated abi is correct ?

That would have saved me a lot of time and would probably save time for many more to come.

0

The issue lies with the ABI you are feeding to web3.eth.Contract and you need a comprehensive one. Go to https://remix.ethereum.org/ and compile your contract there, then copy the ABI from there.

You can find the copy button at the bottom of this image.

You can find the copy button for the ABI at the bottom of this image.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.