Metamask payment button for nft contract

i already have a working code for my ā€œmint buttonā€ but i only can accept a constant amount of crypto .
i want to know how i can make the user choose the amount of nfts to mint with the crypto charge going up as he chooses more nfts to mint. (example: 1NFT=>0.1 ETH / 2NFT=>0.2 ETH / 3NFT=>0.3 ETH ā€¦)
this is the code iā€™m working with right now .
`
window.addEventListener(ā€˜loadā€™, async () => {
if (window.ethereum) {
window.web3 = new Web3(ethereum);
try {
await ethereum.enable();
initPayButton()
} catch (err) {
$(ā€™#statusā€™).html(ā€˜User denied account accessā€™, err)
}
} else if (window.web3) {
window.web3 = new Web3(web3.currentProvider)
initPayButton()
} else {
$(ā€™#statusā€™).html(ā€˜No Metamask (or other Web3 Provider) installedā€™)
}
})

const initPayButton = () => {
  $('.bn632-hover.bn24').click(() => {
    // paymentAddress is where funds will be send to
    const paymentAddress = 'my wallet adress'
    const amountEth = 0.23

    web3.eth.sendTransaction({
      to: paymentAddress,
      value: web3.toWei(amountEth, 'ether')
    }, (err, transactionId) => {
      if  (err) {
        console.log('Payment failed', err)
        $('#status').html('Payment failed')
      } else {
        console.log('Payment successful', transactionId)
        $('#status').html('Payment successful')
      }
    })
  })
}`

Hey youā€™re wanting to mint, but looks like youā€™re just trying to send ether there to the contract, you should instead interact with contract instance to call the mint function and send the ethers value through msgValue

1 Like