0

I'm trying to call a Solidity function from App.js, but I'm unsuccessful even after a number of tries.

Its a very simple function betOnTeam(). Inside this function I just want to check condition and give a call to another function update(), but I'm not even able to view logs in the console (can't even call betOnTeam()).

So here is the function in .sol file that I'm trying to call:

function betOnTeam(uint team) public {
  emit LogInfo("Inside betOnTeam-----------");
  if(team == 1) {
    update();
  }
}   

This function accepts an int so I'm providing it through App.js:

function ready(){
  document.getElementById("bet").addEventListener("click", function(e){
    var contract = web3.eth.contract(OraclizeContract.abi).at(OraclizeContract.address);

    var team = document.querySelector("#bet #team").value;

    if(team == "Home")
    {
      team = 1;
    }
    else
    {
      team = 2;
    }
    console.log(team) ------------>> THIS SHOWS 1 IF HOME SELECTED

    // Now i am calling the .sol function

    contract.betOnTeam(team, function(err, transactionHash) {
      if (!err)
        console.log(transactionHash); 
    })   
  })
}

Any help is highly appreciated.

I can'not call the function by passing the argument I have even tried

contract.betOnTeam.call(team, function(err, transactionHash) {
  if (!err)
  console.log(transactionHash); 
})   

.call gives me a blank array on the console nothing else otherwise without using .call I can'not see any error on the console

update() function:

function update()
  payable
  public {
  // Check if we have enough remaining funds
  if (oraclize_getPrice("URL") > address(this).balance) {
    emit LogInfo("Oraclize query was NOT sent, please add some ETH to cover for the query fee");
  } else {
    emit LogInfo("Oraclize query was sent, standing by for the answer..");

    // Using XPath to to fetch the right element in the JSON response
    oraclize_query("URL", "json(https://api.crowdscores.com/v1/matches/123945?api_key=93c4c515196741beaf5e4528b64ea511).outcome.winner");
  }
}
  • any help is highly appreciated, I cannot call the function if you cant understand the question I am really trying my best to explain I can explain again. Please help if you know anything – raghav Jan 22 at 9:33
  • can you change var team = document.querySelector("#bet #team").value; to var team = document.querySelector("#bet", " #team").value; and try. – Yahya Jan 22 at 11:31
  • please also mention the web3 version you are using. – Yahya Jan 22 at 11:36
  • "web3": "^0.20.0", – raghav Jan 22 at 11:38
  • nope by changing i can't even access the value right now i can access the value as shows in the code -->> console.log statement – raghav Jan 22 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.