-1

I am trying to call a solidity function and am getting an error. This is how I create my contract:

var EthProjContract = web3.eth.contract(my abi);
var EthProj = EthProjContract.at('0xcce478FDeF9F1DF933e31B1eeA48561e0095628A');

I am calling my function like this:

EthProj.setMessage.sendTransaction(shoco.compress(document.getElementById("MessageBox").value), {from: document.getElementById("add").value})

and get this error:

Uncaught Error: Invalid number of arguments to Solidity function

If you are wondering what shoco.compress is, it compressed my strings into uint8arrays. For example,

shoco.compress("Hello") returns Uint8Array(3) [72, 193, 77]

If I have Hello in my MessageBox box and call

EthProj.setMessage.sendTransaction(shoco.compress(document.getElementById("MessageBox").value), {from: document.getElementById("add").value})

I get the error. But, when I call

EthProj.setMessage.sendTransaction([72, 193, 77], {from: document.getElementById("add").value})

it works perfectly. This means it can't be anything with getting my text. So what could it be? All I could think that it could possibly be is that Uint8Array(3) being in there could be messing it up. If so, how could I fix that?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Cal W
  • 167
  • 1
  • 14
  • Sorry, I formatted the code in the post wrong, I edited it to be correct. I think I am on to something on how to fix it though. When I do this: `var message = [0, 0, 0]; message[0] = shoco.compress(document.getElementById("MessageBox").value)[0]; message[1] = shoco.compress(document.getElementById("MessageBox").value)[1]; message[2] = shoco.compress(document.getElementById("MessageBox").value)[2];` And `sendTransaction` using message as my argument, it works. Only if I can make it have something like a variable length. – Cal W May 28 '18 at 12:52

1 Answers1

0

Fixed my error. Here is how I did it.

 var message = [0, 0, 0];
        for(var i = 0; i < shoco.compress(document.getElementById("MessageBox").value).length; i++) {
            message.length = shoco.compress(document.getElementById("MessageBox").value).length;
            message[i] = shoco.compress(document.getElementById("MessageBox").value)[i];
        }

I discovered that it was not working because it said uint8array in the return of shoco.compress. I fixed this by creating a new array and setting that array to be equal to my shoco.compress, getting rid of the uint8array.

Cal W
  • 167
  • 1
  • 14