0

I am trying to create a new contract on button click using Meteor and TemplateVar. The relevant code is:

Template.Borrower.events({
  'click button'(event, instance) {
    // Create new Borrower
    var _borrower = "ABC"

    alert("I am working on it...")

    web3.eth.accounts.wallet.add("0x...");

    var newBorrower = web3.eth.contract(borrowerABIArray).new(_borrower,{from:eth.accounts[0],data:borrowerData,gas:500000}, function(err, newContract){
    if(!err) {

      if(!newContract.address) {
        alert("Contract transaction sent: TransactionHash: " + newContract.transactionHash + " waiting to be mined...");

      } else {
        alert("Contract mined! Address: " + newContract.address);
      }

    }
});

I don't even get an error, it just displays the first message "I am working on it..." and then nothing. I am logged into Metamask so my wallet is unlocked but I did try unlocking it as well and that did not work either.

When I deploy the contract directly with Remix it takes less than 300000 gas so it can't be a gas problem.

Thanks for your help.

0

So I figured it out. I first needed to define newBorrower as a new instance of the contract:

newBorrower = new web3.eth.contract(borrowerABIArray)

Then the code works and mines a new Borrower.

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.