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() {
    myOriginator.makeLoan($("#loanID").val(), borrowerAddress, $("#loanAmount").val(), (err, res) => {
        if (!err) {

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

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

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

Any suggestions?


1 Answer 1


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) {

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")! Commented Mar 21, 2018 at 5:41

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.