Can’t Call Payable Function from Web3

erc-721payablesolidity-0.8.xweb3js

I am trying to call a public payable function from my smart contract (^0.8.0) in a ropsten testnet

    function purchaseCardPack() public payable {
        require(msg.value == cardPackFee, "VALUE SENT NOT EQUAL TO CARD FEE");
        _createCardPack();
    }

using web3.js

  const buyCardPack = async () => {
    try {
      await NFTContract.methods.purchaseCardPack().send({from: account, value: web3.utils.toWei('0.015', 'ether')});
    } catch(err) {
      console.log(err);
    }
  }

and for some reason seeing the error "Transaction Error. Exception thrown in contract code." in MetaMask before I can even send the transaction.

Please let me know if I am doing anything wrong or if there is any other information I can give. Thanks in advance!
This is the error I am seeing

Best Answer

The problem was with _createCardPack(). I was dividing by 0 (an array of length 0, specifically) in a function that it was referencing. Replacing that with a uint did the trick for me.

Takeaway There was nothing wrong with the payable setup, it was an error upstream in the contract. Hope this helps others :)

Related Topic