-
-
Save ksaitor/6c832c106a8b9aee4f76a9145eb5d764 to your computer and use it in GitHub Desktop.
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> | |
</head> | |
<body> | |
<div> | |
<button class="pay-button">Pay</button> | |
<div id="status"></div> | |
</div> | |
<script type="text/javascript"> | |
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 = () => { | |
$('.pay-button').click(() => { | |
// paymentAddress is where funds will be send to | |
const paymentAddress = '0x192c96bfee59158441f26101b2db1af3b07feb40' | |
const amountEth = 1 | |
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') | |
} | |
}) | |
}) | |
} | |
</script> | |
</body> | |
</html> |
Hello! Thank you very much for the code!!
I would like to add a data string on the transaction. Nevertheless, I cannot find the way to do it. Anybody can give me a hand to point me into the right direction?
Thanks!!
Is there a way I can embed some Metamask code on my s]=Squarespace website so that I can allow Metamask payments - for example, can I copy and paste some code into the website to make a fully functioning wallet connect/Metamask button. I'm happy to pay someone some money if they can help me out.
Is there a way I can embed some Metamask code on my s]=Squarespace website so that I can allow Metamask payments - for example, can I copy and paste some code into the website to make a fully functioning wallet connect/Metamask button. I'm happy to pay someone some money if they can help me out.
Hey, 4Jamo!
I'm currently building EtherForms, a tool that will allow you to do exactly what you want, without coding skill requirements.
We were formed at ETHAmsterdam, and are currently building out our public launch.
Would be happy to help you 1:1 to get you setup! :)
You can join our Discord (link on website), and I'll be happy to assist you, free of charge.
Hi.
Thanks for the code. But it not working in mobile app. Have you any idea?
How to take get payment in BUSD not in ETH ?
I also want to know. Is there a way to do it with BUSD or USDT instead of ETH(BNB)? please suggest some way to do it.
I also want to know. Is there a way to do it with BUSD or USDT instead of ETH(BNB)? please suggest some way to do it.
Check here to take payment in BUSD or BNB
thank you
thank you
I will update this code with wallet model so it will work on safari or mobile as well. right now this code is only for chrome/firefox with metamask ext only
You can also choose to use CryptoPay, our all in one crypto payments solution for your WordPress sites.
Review the CryptoPay: https://beycanpress.com/cryptopay/
Tried this and I think it's a bit outdated. Here's how i tested it:
http-server
(npm install -g http-server
)<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
(https://github.com/ChainSafe/web3.js#in-the-browser)web3.toWei()
toweb3.utils.toWei()
(https://ethereum.stackexchange.com/questions/48068/error-web3-towei-is-not-a-function)from: MYROPSTENADDRESS
inweb3.eth.sendTransaction
(I burned the string here since didn't what to spend too much time in the async ways of getting the addres from)I've might have forgete something I did so I'm adding the result:
https://gist.github.com/El-JojA/2cca7b2e136aca4f28094d29707cc1c3