0
votes

Wrote this simple solidity contract where the functions accept a few parameters.

function fund(uint _dbIndex, uint _fundedAmount) public {
    uint totalAmount = projectWallets[_dbIndex].fundedAmount;
    totalAmount += _fundedAmount;
    projectWallets[_dbIndex].fundedAmount = totalAmount;
}

after creating this smart contract, i tried connecting the SC to a HTML page with javascript. I managed to get a function without parameters to work but couldnt get it to work if theres parameters in the function..

<input type="number" min="0" placeholder="Fund Amount" style="color: black;" id="fund">
<button id="fund_project">Fund Project</button>

above is the input and button to send the value into the smart contract.

$('#fund_project').click(function (e) {
  e.preventDefault();

  log("Calling fund function...");

  counter.fund(dbIndex, funds);
});

and this is a segment of the code where i take in the function with parameters. How do i get it to work?

1
Where are dbIndex and funds defined? - user94559
What error do you get? If you don't get an error, what is it that's not working properly? - user94559
i was defined inside the contract. just showing how i did the function. the error i got was "Uncaught Error: The MetaMask Web3 object does not support synchronous methods like eth_sendTransaction without a callback parameter." - Adam Chua
Is there something about the error you don't understand? (Do you not know what a callback is?) - user94559
I dont quite understand it yeah. forgotten to include the error before i submitted the question yeah - Adam Chua

1 Answers

0
votes

A callback is a function that is called when the operation is complete. You need to use one, e.g.:

counter.fund(dbIndex, funds, function (err, result) {
  if (err) {
    console.log('Error: ' + err);
  }
  else {
    console.log(result);
  }
);