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

contractInstance.options.jsonInterface is undefined #2494

Closed
rjkz808 opened this issue Mar 13, 2019 · 2 comments
Closed

contractInstance.options.jsonInterface is undefined #2494

rjkz808 opened this issue Mar 13, 2019 · 2 comments
Labels
Documentation Relates to project wiki or documentation

Comments

@rjkz808
Copy link

rjkz808 commented Mar 13, 2019

Description

There's no JSON interface when I'm accessing the contract instance options.

Source code

// The contract ABI and address are defined correctly,
// the web3 object is initialized correctly too
const contractInstance = new web3.eth.Contract(abi, address);
console.log(JSON.stringify(contractInstance.options));

Expected behavior

The above code should output all the contract options, including the JSON interface (ABI).

Actual behavior

The above code output is next:

> {"transactionSigner":{"utils":{},"formatters":{}},"address":"0x58bFaAb4fe3D8CE06Eeb3d0A565aBF25c53db0Ce"}

As you can see, there's no jsonInterface in the logged options.

Also, when I'm trying to access the JSON interface in code

contractInstance.options.jsonInterface.forEach(console.log);

It throws a TypeError: Cannot read property 'forEach' of undefined

Steps to reproduce the behavior

This behavior is reproducible with any created contract instance, just try to access the contractInstance.options.jsonInterface.

Versions

  • web3.js: 1.0.0-beta.48
  • Node.js: 10.15.1
  • Brave Browser: 0.60.48
  • Chromium: 72.0.3626.121 (Official Build) (64-bit)
  • MetaMask: 6.2.2
@nivida
Copy link
Contributor

nivida commented Mar 13, 2019

I've simplified the AbstractContract object to be consistent with the other module options and the jsonInterface property returns now an AbiModel with some additional methods to check for or to get a ABI item.

contract.jsonInterface
contract.address
contract.defaultAccount
contract.defaultGas
contract.defaultGasPrice
...

I could add the contract.options but the code behind the scene wouldn't be that clean. Is it also a solution for you when I keep it the way it is now and I'm updating the documentation?

I apologize for this change and I'll give my best to write asap integration tests for having a proof that nothing breaks on a change.

@nivida nivida added Bug Addressing a bug Discussion labels Mar 13, 2019
@rjkz808
Copy link
Author

rjkz808 commented Mar 13, 2019

I've simplified the AbstractContract object to be consistent with the other module options and the jsonInterface property returns now an AbiModel with some additional methods to check for or to get a ABI item.

contract.jsonInterface
contract.address
contract.defaultAccount
contract.defaultGas
contract.defaultGasPrice
...

I could add the contract.options but the code behind the scene wouldn't be that clean. Is it also a solution for you when I keep it the way it is now and I'm updating the documentation?

I apologize for this change and I'll give my best to write asap integration tests for having a proof that nothing breaks on a change.

Ok, I think new solution is better than the one that was before. The only thing you need to fix is web3 documentation. I hope you'll close this issue after that 😄

@nivida nivida added Documentation Relates to project wiki or documentation and removed Bug Addressing a bug Discussion labels Mar 13, 2019
@nivida nivida mentioned this issue Apr 3, 2019
12 tasks
@nivida nivida closed this as completed Apr 4, 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
Documentation Relates to project wiki or documentation
Projects
None yet
Development

No branches or pull requests

2 participants