Welcome to second article of Metamask integration with Laravel.
This document is related to my 1st document. which I explained about Metamask integration with Laravel.
you may read it here ->
Metamask Integration With Laravel
Lathindu Pramduitha γ» Feb 10 '21
Okay, Let's start second part of the article now.
How to validate transactions which are made with Metamask
here I'm using images instead of pasting codes here, it's easy to write document.
and what a wonderful, you can copy or refer full code in repository which I'm mentioned end of the document. π
For the validate transactions very easy and free method is a EtherScan API.
First of all, Let's create Etherscan account.
Now we need to create API key
step 01
step 02
step 03
Now you may copy the key and store in somewhere for use in our application.
Next we need to create command in Laravel for add to shedular.
I have created a Command called MetamaskValidationCommand
You may open the command file in your editor [ My favourite is VSCode π ]
App->Console->Commands->MetamaskValidationCommand.php
How To Validate?
For validate a transaction we can use EtherScan 's Free API.
You can see number of methods in EtherScan API.
Here we use eth_getTransactionByHash method only.
we have to send 2 parameter with this simple get request.
- API Key => We already made a one π
- Transaction Id => It's we already stored in database as txHash π₯³
above we created a command called MetamaskValidationCommand
it's time to code.π§π»βπ»
code step 01
Create a function to get transaction information from EtherScan. inside MetamaskValidationCommand.php
code step 02
Now we need to get pending transactions from database.
here we need to add some delay to get transactions. because some time Etherium transactions may take more time to be a successful transaction. so here we get transactions which are older than 20 minuets and status = pending from database.
To call Transaction Model we need call modal inside our constructor.
Now we need to create get function inside Transaction Model.
Then we can create a function for validate transactions inside MetamaskValidationCommand.php
Here we first get all the pending [older than 20min] transactions and loop them inside foreach.
then we get them one by one and send transaction id (txHash) to EtherScan by using function which we mede above ( code step 01 ).
so our functions are ready to use.
Now we need to modify our command with custom command params.
finally we need to add our command to kernel.php
app => Console => kernel.php
here I'm adding schedule to run command every Minuit. You are free to change for any time range --> References.
Now we are ready to test.
01 make a transaction like I described in Article 01.
02 Wait At least 20 Minuit (You may change the delay value inside TransactionModel.php).
03 You can see it's marked as success. if its success payment.
I think your transaction also succeeded without an error. any error please comment below I will help you guys to success.
Important
In these both tutorials I have described as very basic methods. we don't write codes like that in production sites. we need to think more about security and durability. I guest you may got help from my article.
You may Find my Fiver Gig Here.
https://www.fiverr.com/s2/0c68721323
here You may read article one
Metamask Integration With Laravel
Lathindu Pramduitha γ» Feb 10 '21
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 π€.
GitHub Repository
Tutorials
Here I will show all the code blocks of my tutorials. you can copy anything or learn anything.
Articles
Thank You Very much.
- Lathindu Pramuditha.
- GitHub Profile -> https://github.com/lathindu1
Top comments (1)
thanks you . Can you also show how accept payment by metamask in laravel