What Is MetaMask ?
MetaMask is a cryptocurrency wallet which can be install in several browsers such as Chrome, FireFox and Brave Browser [ Unfortunately you canβt install in Safari π€ͺ ]. That mean you can use Metamask as a bridge between ETH blockchain and browser.
And what is the amazing one, You can store ERCi20 token also in Metamask like ETH.
So you can build custom token and use it inside your platform.
So How To Integrate ?
Letβs go with Metamask integration process.
Here Iβm use simple Laravel application to show entire integration process.
And I'm using screen shots of my code to make this article much easier.
πͺ Don't Worry End Of the Document I will mention the GitHub repository and also Codepen link. then you can get entire code π.
So letβs divide process as a two sections.
- How To Integrate Metamask.
- How To Validate Transactions.
In this article I will describe the step 01.
01 How To Integrate Metamask
Here Iβm using Chrome as my browser.
Step 01
Letβs create simple input with button for enter the amount.
Step 02
Now we need to create javascript function to submit payment. Here I add function with onClick event of the button.
Step 03
Now we need to create javascript function to initialise, metamask and run payment.
Before that let's simplify the process which we need to do here.
1 Web3 Browser Detection
2 Connect to MetaMask Account
3 Do A Payment
so here I'm adding some major validations to make process more creative. and also we must use javascript await expression because of async process.
1 Detect Web3
2 Connect With Metamask Account
3 Do Payment
here you can see I mentioned a place where you should enter the payments receive address. for testings you can simply create two accounts in metamask and use one account for receive payments and second account for make payments.
after this step we can do a payments with Metamask , without an issue.
Then we need to store transaction in the database.
for that I will use simple Ajax Request for send data to TransactionController.
Now we need to show all the transactions to user.
first get transactions from the transactions table.
Now we can show all the transaction in simple bootstrap table.
finally transactions page will looks like this.
Okay Grate π Now all the steps are completed.
** When you try to make a transaction. In Very first attempt Metamask will ask to connect your one of account. So here you must connect your account with your website [This process need only first attempt]. Then you can send payments. but if you have already connected account you can pay directly**
let's try to make a transaction.
Then Verify Our Payment With Etherscan.
Simply copy transaction id and put in Etherscan transaction id box.
or you can use Link Like this.
https://ropsten.etherscan.io/tx/{Your_Transaction_Id}
Here ropsten is our network.
for the testings we can use ropsten network. and make sure when you go live you must use Mainnet as your network.
Test Transaction Example in Etherscan.
In Next Article I will guid You To Make Validator to validate transactions.
I think if you read carefully you may learn something new.
Here I'm Adding Public GitHub Repository which will store all of my tutorials. you may clone it and see every tutorials what I will publish π€.
You may Find my Fiver Gig Here.
https://www.fiverr.com/s2/0c68721323
You may read second Article Here
Metamask Integration With Laravel Part 2[ Validate Transactions With EtherScan ]
Lathindu Pramduitha γ» Feb 16 '21
GitHub Repository
Tutorials
Here I will show all the code blocks of my tutorials. you can copy anything or learn anything.
Articles
CodePen
Thank You Very much.
- Lathindu Pramuditha.
- GitHub Profile -> https://github.com/lathindu1
Top comments (5)
I find this helpful. Thanks alot
hi can you help me? i connected metamask and pay button is working but i cant call transactions. Can you send only this pages pls? help me
what should i put to receive BUSD?
Works like magic!!! love it,Thankyou
cant run on my localserver.
can you help me!