0

I declared the variables as follows

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import Web3 from 'web3';

  var ETHEREUM_CLIENT = new Web3(new Web3.providers.HttpProvider("http://localhost:9545"));
  var contractABI = [{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"Candidates","outputs":[{"name":"firstName","type":"bytes32"},{"name":"lastName","type":"bytes32"},{"name":"age","type":"uint256"},{"name":"group","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getCandidate","outputs":[{"name":"","type":"bytes32[]"},{"name":"","type":"bytes32[]"},{"name":"","type":"uint256[]"},{"name":"","type":"bytes32[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_firstName","type":"bytes32"},{"name":"_lastName","type":"bytes32"},{"name":"_age","type":"uint256"},{"name":"_group","type":"bytes32"}],"name":"createCandidate","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]
  var contractAddress = '0x345ca3e014aaf5dca488057592ee47305d9b3e10';
  var CandidatesContract = ETHEREUM_CLIENT.eth.contract(contractABI).at(contractAddress)

But React returns a Type error as 'TypeError: ETHEREUM_CLIENT.eth.contract is not a function'

The same function working properly in Browser console, when i declare the variables directly put into the console?

can you please fix it?

  • Is ETHEREUM_CLIENT loaded correctly? – Luiz Soares Nov 29 '17 at 11:42
  • Thanks @LuizSoares, It is just because of the version of web3 that i'm using. I used a latest beta version, I think the function 'contract' is actually modified into 'Contract' in its latest version. So when i roll back to the web3 version 0.20 the problem got solved. – Akash Nov 30 '17 at 5:35
0

Got solved. It is just because of the version of web3 that I'm using. I used the latest beta version, I think the function 'contract' is actually modified into 'Contract' in its latest version. So when I roll back to the web3 version 0.20 the problem got solved

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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