1

I have an HTML front-end that calls a function in a contract to create/deploy another contract. The function works standalone in remix. I get an error "Uncaught Error: Invalid number of arguments to Solidity function" but I send the right number of elements. The javascript code is:

var borrowerAddress = '0x...';
$("#makeLoanButton").click(function() {
    $("#loader").show();
    myOriginator.makeLoan($("#loanID").val(), borrowerAddress, $("#loanAmount").val(), (err, res) => {
        if (!err) {
           $("#loader").hide();
        }
   });
});

the solidity code is:

    function addLoan(address _newLoan) public {
        // Add loan to originator
        Loan myLoan = Loan(_newLoan);
        loans.push(myLoan) -1;
        originatorLoanBalance += myLoan.getBalance();

    } // function addLoan(address _newLoan) public {

function makeLoan(bytes16 _loanID, address _borrower, uint _loanBalance) payable public {
    // Create new loan
    Loan myLoan = new Loan(_loanID, _borrower, address(this), _loanBalance);

    // Add loan to loans
    loans.push(myLoan) -1;

    // Now add new loan to array
    addLoan(address(myLoan));

    // Send loan balance to borrower
    if (!_borrower.send(_loanBalance)) {
        revert();
    }

} // function makeLoan(bytes16 _loanID, address _borrower, uint _loanBalance)

Any suggestions?

Thanks!

2

try to set the transaction object, since your function is payable

myOriginator.makeLoan($("#loanID").val(), borrowerAddress, $("#loanAmount").val(), {value: 1, gas: 2000}, (err, res) => {
        if (!err) {
           $("#loader").hide();
        }
   });

note: you can actually remove _loanBalance and use msg.value since your function is payable

  • 1
    Thanks for the reply. I figured the problem out. It was not a problem with my syntax but rather that I was referring to the wrong HTML ID! It should have been $(#loanBalance") instead of $(#loanAmount")! – Philip Rutovitz Mar 21 '18 at 5:41

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.