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?