Sending an argument with an ethers contract object

I’m trying to interface with my tested (in Remix) and working contract in a browser now but cannot understand how to send additional arguments with a payable function.

I need to pass an argument userTeamChosen with a appendUserBet() function which I both set the values for through html forms but get this error Error: cannot estimate gas; transaction may fail or may require manual gas limit and have no idea whether im sending the argument correctly or not.


<body>   <label for="fund">ETH Amount</label>   <input id="ethAmount" placeholder="0.1" />   <input id="betTeam" placeholder="Team name" />   <button type="button" id="appendBetButton"> appendBetButton </button> </body>  <script src="./index.js" type="module"></script> 

smart contract function:

    function appendUserBet(string memory userTeamChosen) public payable {         uint256 minimumFee = 1 * 10**17 wei;         userList.push(payable(msg.sender));         require(msg.value >= minimumFee);         fee = msg.value;         userStructs[msg.sender].betAmount += msg.value;         userStructs[msg.sender].teamChosen = userTeamChosen;     } 

and this is where I interact with it in index.js:

async function appendUserBet() {     const ethAmount = document.getElementById("ethAmount").value     console.log(`Funding with ${ethAmount}...`)     if (typeof window.ethereum !== "undefined") {         const provider = new ethers.providers.Web3Provider(window.ethereum)         const signer = provider.getSigner()         const contract = new ethers.Contract(contractAddress, abi, signer)         try {             const transactionResponse = await contract.appendUserBet({                 value: ethers.utils.parseEther(ethAmount), userTeamChosen: "sab", gasLimit: 50000             })             await listenForTransactionMine(transactionResponse, provider)         } catch (error) {             console.log(error)         }     } else {         appendBetButton.innerHTML = "Please install MetaMask"     } } 

Can somebody please let me know how to add the needed string argument to a payable function in a js interface with ethers?

Thanks alot for your time in advance!

Sending an argument with an ethers contract object

Shopping cart
There are no products in the cart!
Continue shopping