0

I'm trying to deploy contracts using Ganache but I'm getting the following error.

I have my ABI and contract address defined, all other functions with respect to interacting with the contract work, however I cannot create a new one. Any ideas? Thanks.

The code is below...

newContract: function(error, result) {
  createContract.new(quantity,name,decimals,symbol,{from:account,gas:21000}).then(function(instance) {

  if (!instance.address) {
    console.log("Contract at: " + instance.transactionHash + " waiting to be mined");

  } else {
    console.log("Contract mined. Here it is: " + instance.address);
    console.log(contract);
  }

  console.log(instance.address);    
});

This is the error -

TypeError: createContract.new is not a function

Update: It is initialized via

var createContract = web3.eth.contract(createContractabi);

I'm wondering if the error is being generated as my currentprovider is giving an error...

Both createContract.setProvider(this.web3.currentProvider); and createContract.setProvider(web3.currentProvider); were tried.

However, both fail, with the errors

TypeError: Cannot read property 'currentProvider' of undefined

and

TypeError: createContract.setProvider is not a function

respectively.

  • You're missing some code. How is createContract initialized? You should have something like const createContract = web3.eth.contract(abi); somewhere. – Adam Kipnis Jan 19 '18 at 4:58
  • Thanks for the reply. It was always initialized...but unfortunately the error is still occurring. – jack bauer Jan 19 '18 at 7:33
  • .new is for 0.17 and above. If you are using 1.0.0, use this: web3js.readthedocs.io/en/1.0/web3-eth-contract.html – Florian Castelain Jan 19 '18 at 7:47

Your Answer

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

Browse other questions tagged or ask your own question.