0

TL,DR: Is anyone also experiencing problems with the Web3JS documentation?

I am very confused by the API documentation of Web3Js because of its behaviour.

(1)

var myContract = new web3.eth.Contract(abi, address);

Error: VM4943:1 Uncaught TypeError: web3.eth.Contract is not a function at :1:10

But when I use...

var myContract = new web3.eth.contract(abi, address);    // Minor c

it is working just fine.


(2)

var contract2 = contract1.clone();

Error: VM5261:1 Uncaught TypeError: contract3.clone is not a function at :1:11


(3)

My aim is to create a default contract (already done), clone/copy it. But I am stuck where it comes to receiving the contractAddress from the newly created contract:

var SampleContract = eth.contract(abi);

var contractInstance = new SampleContract.new(30, {data: byteCode, from: firstAccount, gas: estimate, gasPrice: estimate});

...

Thank you in advance!

0

1 Answer 1

1

You're reading the documentation of version 1.x, but you're using version 0.x.

3
  • Thanks for the quick response :) I am using 1.2.7 (cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js) and also reading it... Commented Apr 28, 2020 at 18:58
  • @Hashtag3232: No you're not! The syntax web3.eth.contract (with a lower-case c) is of v0.x. Note that you may have web3.js v1.x installed in one place and web3.js v0.x installed in another place, which is where your script imports it from. For example, if you're using Truffle v4.x or lower, then it internally relies on web3.js v0.x. So in all of your Truffle tests, web3.js v0.x will be automatically (and implicitly) imported. Commented Apr 28, 2020 at 19:02
  • Thanks! I am using Wordpress it was somehow already an old version installed (0.2.0) -> var version = web3.version.api; Commented Apr 28, 2020 at 19:54

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.