HACKER Q&A
📣 thedangler

Accepting ETH payments on my website


Hello, Wondering how I can accept crypto payments, mainly eth, on my site. I know there are crypto payment gateways, but I want to do this myself.

I see there is a way to do it with metamask but I can't seem to find the answer to one question.

Does the end user need a metamask wallet to payment on my site?

When looking at the code it suggests that but I'm not sure. And that seems rather limiting.

Thanks for the help.


  👤 brendanmc6 Accepted Answer ✓
Paying with ETH is the easy part— few lines of javascript using Ethers.js

The hard part is managing wallet connections, and then automating what happens after payment is complete.

For wallet connections I use web3modal.

For reconciling the purchase after payment, no clue. I use coingate for crypto checkouts for this reason. There are probably backend libraries out there to help you track and respond to transaction events on a given address. Let me know what you find!


👤 davidajackson
No they don't need metamask. Try the following:

1. Generate payment destination address info: web3.createaccount() on backend, or even have a list of PUB keys on backend that link to ideally cold wallets. The point I'm trying to make is to isolate the destination PK's far away from frontend.

2. Send pub key to frontend and present to user in UI.

3. On backend, listen for incoming ether transfers (if you reuse wallets, consider creating a smart contract to allow a function call that allows you to pass data to identify sender to avoid duplicate payment amount confusion). Have frontend react when payment complete. Consider temp payment addresses 'hot' and move funds to cold ASAP, a common pattern you'll see.

When you get into more complicated interactions, it does become a rabbit hole of complexity.

I did just release an API for launching NFTs that has a concept of funding accounts: https://www.bridge-api.com/ (beta stage). If at some point you are looking for a larger solution and want to chat where you can manage many accounts without all the hassle of gas estimation, gas price, ABIs, etc., shoot me an email (email in profile). I am looking to talk to early stage founders.


👤 turdnagel
The "low level" way is - you can use a web3 library like web3.js or ethers.js to let the user connect their MetaMask wallet. You would have to expose your wallet address and make a call to `sendTransaction`.