1

I am running a Meteor application and faced with an error I cannot figure out. I am using a quick form to insert a document into a collection and one of the fields is a Hash address to be obtained from a web3 api call using auto value.

//Schema with autovalue to obtain hash address via web3 call
CustomerSchema = new SimpleSchema({
  customerBlockchainAddress: {
    type: String,
    label: "Blockchain Address",
    autoValue: function() {
         var address = web3.personal.newAccount("password");
         console.log("Address: ", address);
         return address;
     },
     autoform: {
         type: "hidden"
     }
  },
//additional schema fields 

The method is invoked by a quick form. See below:

//HTML
<template name="NewCompany">
    <div class="new-document-container">


    {{#if isSuccessfulCompany }}
        <h3 class="success">Successfully registered company information. <br /> <br /> </h3>
    {{else}}
        <h3>Register Company Information:</h3><br />
        {{> quickForm collection="Companies" id="insertCompanyForm" type="method" meteormethod="insertCompany" class="new-Company-form"}}
    {{/ if}}

</div>

Insert method:

insertCustomer:function(customer){
    CustomerSchema.clean(customer, {
      extendAutoValueContext: {
        isInsert: true,
        isUpdate: false,
        isUpsert: false,
        isFromTrustedCode: false
      }
    });
    check(customer, CustomerSchema);
    if (! this.userId) {
        throw new Meteor.Error('not-authorized');
    }
    if(! Roles.userIsInRole(this.userId,'individual')){
        throw new Meteor.Error('not-authorized for your role');
    }
    //custom API that takes fields from the customer doc and stores    
    them on the blockchain
    Meteor.call('individualRegistration', customer, function (error,            
    result) {
             if (error) {
                 console.log("error", error);
             };
             console.log(result);
         });
    return Customers.insert(customer);
}

The error I am getting is:

Exception while invoking method 'insertCustomer' TypeError:       
XMLHttpRequest is not a function

Using log statements, the AutoValue function is obtaining a new address from the web3 call as expected but it is printing four times with different addresses before the error is thrown. If I hard code the address with just a string, the insert function works properly as expected with the custom API.

Any help in understanding this error would be greatly appreciated.

Thanks

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.