How to add Ethereum payments to your site with MetaMask
About a year ago I’ve uploaded a quick Ethereum and Metamask coding guide on YouTube:
Today, due to popular demand, I’d like to write a quick article on adding Ethereum payments to your website. This guide assumes that you are new to programming, and I’ll try to avoid referencing complex web dev frameworks like React… Knowing basic jQuery will suffice here.
Let’s get your set-up ready, step by step:
- Make sure you have Metamask installed.
- For development, switch to Ropsten or Kovan development network.
- Get some Ether in your account on a test network via https://faucet.metamask.io/
- Copy paste this code
5. Serve your html file through a server. E.g. with https://www.npmjs.com/package/serve. If you’ll open your html file directly in the browser, Metamask won’t be injected (for security reasons).
This is what you get:
At the core of this function is sendTransaction(). You can read more about it in Web3 Docs. I’d generally recommend reading the docs in and out, but i also understand that what 99% of people want is just a simple guide to making payments.
Please write down your questions in comments below — I’ll be answering them and improving this article too.