0

So, I tried the many examples found around but I never manage to get it working.

I have this snippet:

async function pay(cost) {
        code = 0
        message = "Please approve the tx"
        if (typeof address == 'undefined') {
            alert("Please connect to your metamask.")
        }
        const paymentAddress = 'MY_ADDRESS'
        const amountEth = cost.toString()
        var web3 = new Web3(Web3.givenProvider)
        res = web3.eth.sendTransaction({
          from: address,
          to: paymentAddress,
          value: web3.utils.toWei(amountEth, 'ether')
        }, (err, transactionId) => {
          if  (err) {
            console.log('Payment failed', err)
            code =-1
            message = "Failed"
            return message;
          } else {
            console.log('Payment submitted', transactionId)
            code =1
            message = transactionId
            return message;
          }
        })
    return res;
}

Which is working great in requesting a value in ETH when connected to the ETH Mainnet.

My dapp should be able to request BNB if connected to BSC or FTM if connected to Fantom.

I managed to create a connection thus i have the address, chainid and so on. I tried simply changing the cost, it doesn't work.

How one can do this?

3
  • It should work for any network, what error are you getting?
    – Ismael
    Commented Nov 1, 2021 at 5:43
  • it just return transaction denied without even showing anything on console or other things. Could you try if it works on your side? @Ismael Commented Nov 1, 2021 at 19:06
  • What wallet/provider are you using? That error message may indicate a problem with the provider.
    – Ismael
    Commented Nov 1, 2021 at 21:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.