0

function TriggerContract() { var account = getAccounts(); var test = web3.eth.defaultAccount;

    console.log(account);
    var q = document.getElementById("Quantity").value;
    var u = toHex(document.getElementById("Unit").value);
    var m = toHex(document.getElementById("Material").value);
    var x = contractAddress.countMaterials(function(err, result) {
          if (err) {
            console.log(err)
          } else {
            console.log("Hey")
          }
        });
    console.log(x);
    contractAddress.setMaterial((test,q, u, m) => {
          if (err) {
            console.log(err)
          } else {
            console.log("YES")
          }
        });
    Reset();
  }

I get a "Uncaught Error: Invalid number of arguments to Solidity function" on the following line and have no idea why. The number of arguments should be correct. Any suggestions would be greatly appreciated.

contractAddress.setMaterial((test,q, u, m)

function setMaterial(address _address, uint64 _weight, bytes16 _material, bytes16 _unit) public{
        materials[_address] = Material(_address, _weight, _unit, _material);

        materialAccounts.push(_address) -1;
        emit materialAdded(_materialID);
    }
  • The function below does work and this problem only seems to arise when I am trying to pass variables to my contract. contractAddress.countMaterials(function(err, result) { if (err) { console.log(err) } else { console.log("Hey") <!--store.dispatch('pollWeb3', {q: q})--> } }); – Macdara Day Feb 18 at 22:31
1

I believe it is due to the absence of proper callback function. Please try below format and also try without result part( only err).

 functionname  (variables,function (error, result) {

              if (error) {
                  console.log(error)
              }
              else {
            console.log("yes")

              }
0

Change this:

    contractAddress.setMaterial((test,q, u, m) => {

To this:

    contractAddress.setMaterial(test,q, u, m).then(function(result, err) => {

Since I usually resolve promises with an await rather than a callback function, I'm not 100% sure about the prototype of function(result, err). You should possibly use function(err) instead.

  • Thanks for your response however it didn't solve my problem – Macdara Day Feb 18 at 12:42
  • @MacdaraDay: If you're hoping to get some help here, then you should provide a little more than "it didn't solve my problem". I tried to endorse your attention to the incorrect syntax that you are using in contractAddress.setMaterial((test,q, u, m) => {, but your response doesn't refer to that in any way whatsoever. You should kind of understand that this is not a "please solve my problem" service, but rather a platform for solving problems in a manner of cooperation. – goodvibration Feb 18 at 15:33
  • @goodvibrations Sorry I wasn't trying to complain or anything. I really appreciate you helping me I was just saying it to try and keep the thread open incase anyone else would have suggestions. – Macdara Day Feb 18 at 22:25
  • Adding the => causes an error. "Uncaught SyntaxError: Unexpected token =>" and taking it out causes Uncaught Error: Invalid number of arguments to Solidity function – Macdara Day Feb 19 at 10:03

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.