These solidity functions are part of my solidity code which i want to execute them by clickcing on a button on my HTML.One of them stands for accepting bets placeBet() and the other one for sending back the gains to winner gamblers claim().

function placeBet(Side _side) public payable {
    require(msg.value > 0, "Sorry we cannot accept Zero values");
    require(ended == false, "Unfortunately accepting bets is over!!");
    bets[_side] += msg.value;

    function claim() public {
    require(ended = true, "Game is not over yet sir!");
    uint gain = gamblerBet + (bets[result.LOSER] * gamblerBet / bets[result.WINNER])
    remainingWithdrawal -= 1;

Here is my contract instance getting saved into state object.

      const networkId = await web3.eth.net.getId();
      const deployedNetwork = PredictionContract.networks[networkId];
      const instance = new web3.eth.Contract(
       deployedNetwork && deployedNetwork.address,
      this.setState({ web3, accounts, contract: instance });

As you can see first solidity function accepts a parameter which is defined at the beggining of my script as a struct and second function does not need any parameter. I have used truffle react box for user interface.Inside of App.js file after saving the contract instance into the state object i wanted to access its functions as below but it didn't work. Here are a button refers to claim() function and a button for placeBet() in my render section.

<button type="button" onClick={this.claim}>CLAIM YOUR REWARD :)</button>
<input type="button" onClick={this.submitBetA} value="PLACE BET"/>

And finally here are my Javascript functions to connect buttons to their intended smart contract function but it does not work as well.

submitBetA = () => {
this.state.contract.methods.placeBet("0").send({from: this.state.accounts[0], value: this.state.amountA})}
claim = () => {
this.state.contract.methods.claim().send({from: this.state.accounts[0]})}

Values for submitBetA is taken from my state object. Could anyone tell me where is my problem cause the buttons doesn't work properly.

  • When you say "doesn't work properly" what exactly do you mean? transaction fails, it isn't generated, some other error. Also what is Side? You said it is an struct but you send "0" as parameter, is the "0" the correct value? What solidity version are you using?
    – Ismael
    May 17 at 5:30
  • I use "1" and "0" to interact with my function that needs parameter May 18 at 14:48
  • doesn't work properly means By clicking the related button to the function nothing really happens May 18 at 14:49
  • Try adding console.log around the function to determine if the button work. Did you check if anything appears on the browser console?
    – Ismael
    May 18 at 18:54
  • Thanks for the advice friend May 28 at 14:55

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.