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

New web3 release throws a TypeError, while 0.20.0 runs normally #1117

Closed
wrisx opened this issue Oct 15, 2017 · 1 comment
Closed

New web3 release throws a TypeError, while 0.20.0 runs normally #1117

wrisx opened this issue Oct 15, 2017 · 1 comment

Comments

@wrisx
Copy link

wrisx commented Oct 15, 2017

What could be the problem there:

ERROR
TypeError: ETHEREUM_CLIENT.eth.contract is not a function
...src/App.js:12
   9 | 
  10 | let peopleContractABI = [{"constant":true,"inputs":[],"name":"getPeople","outputs":[{"name":"","type":"bytes32[]"},{"name":"","type":"bytes32[]"},{"name":"","type":"uint256[]"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_firstName","type":"bytes32"},{"name":"_lastName","type":"bytes32"},{"name":"_age","type":"uint256"}],"name":"addPerson","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"people","outputs":[{"name":"firstName","type":"bytes32"},{"name":"lastName","type":"bytes32"},{"name":"age","type":"uint256"}],"payable":false,"type":"function"}];
  11 | let peopleContractAddress = '0xa2561ea34138ddddb939e575ef721530e5510d1b';
> 12 | let peopleContract = ETHEREUM_CLIENT.eth.contract(peopleContractABI).at(peopleContractAddress);

The code in the App.js file:

let ETHEREUM_CLIENT = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

let peopleContractABI = [{"constant":true,"inputs":[],"name":"getPeople","outputs":[{"name":"","type":"bytes32[]"},{"name":"","type":"bytes32[]"},{"name":"","type":"uint256[]"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_firstName","type":"bytes32"},{"name":"_lastName","type":"bytes32"},{"name":"_age","type":"uint256"}],"name":"addPerson","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"people","outputs":[{"name":"firstName","type":"bytes32"},{"name":"lastName","type":"bytes32"},{"name":"age","type":"uint256"}],"payable":false,"type":"function"}];

let peopleContractAddress = '0xa2561ea34138ddddb939e575ef721530e5510d1b';

let peopleContract = ETHEREUM_CLIENT.eth.contract(peopleContractABI).at(peopleContractAddress);
...

Again, web3@0.20.0 runs fine, the latest one throws an error on the above code...

@frozeman
Copy link
Contributor

frozeman commented Oct 20, 2017

Hm. Thats probably because 1.0 has a different API as it is a major release. Please read the docs here: http://web3js.readthedocs.io/en/1.0/

Its then let peopleContract = new ETHEREUM_CLIENT.eth.Contract(peopleContractABI, peopleContractAddress);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants