1

I don't get it. I've seeing two ways from tutorials on how to instantiate web3.

One is..

eth = new Eth(web3.currentProvider)
token = eth.contract(abi).at(contract_address);

and another is..

web3 = new Web3(web3.currentProvider);
token = new web3.eth.Contract(abi, contractAddress);

How are they different? And I can't find info on https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html with the small "c" for contract.

1 Answer 1

1

I think I know why. Small "c" is for web3 version below 1.0. Lowercase "c" and no "new". While big "C" is for version 1.0++.

Gosh, why they make like difficult for coders.

2
  • This is indeed the case. In web3 v0.x, use web3.eth.contract. In web3 v1.x, use new web3.eth.Contract. Commented May 13, 2019 at 8:05
  • I have to add that usually class names are capitalized by convention, while it's attributes aren't, as you can see in new Eth, new Web3 and new web3.eth.Contract. Commented May 25, 2019 at 3:43

Your Answer

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

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