This document is related to my 1st document. which I explained about Metamask integration with Laravel.
you may read it here ->
Okay, Let's start second part of the article now.
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.
Now you may copy the key and store in somewhere for use in our application.
I have created a Command called MetamaskValidationCommand
You may open the command file in your editor [ My favourite is VSCode 😊 ]
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
Create a function to get transaction information from EtherScan. inside MetamaskValidationCommand.php
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.
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.
here You may read article one
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 🤗.
Here I will show all the code blocks of my tutorials. you can copy anything or learn anything.
Thank You Very much.
- Lathindu Pramuditha.
- GitHub Profile -> https://github.com/lathindu1