How To Connect Metamask To Etherscan
Welcome to 2nd article of Metamask integration with Laravel.
This document is related to my 1st document. which I explained nigh Metamask integration with Laravel.
you may read it here ->
Okay, Let's start second part of the article now.
How to validate transactions which are made with Metamask
here I'one thousand using images instead of pasting codes hither, it's piece of cake to write document.
and what a wonderful, you lot tin can copy or refer full code in repository which I'grand mentioned end of the document. 😊
For the validate transactions very piece of cake and free method is a EtherScan API.
First of all, Let'due south create Etherscan business relationship.
At present we need to create API key
step 01
footstep 02
stride 03
Now you may copy the key and shop in somewhere for use in our application.
Next we need to create control in Laravel for add together to shedular.
I accept 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 tin can apply EtherScan 'southward Free API.
You tin come across number of methods in EtherScan API.
Here we use eth_getTransactionByHash method only.
we take to send 2 parameter with this unproblematic become request.
- API Central => We already made a one 🎉
- Transaction Id => It's we already stored in database as txHash 🥳
in a higher place we created a command called MetamaskValidationCommand
it'south time to code.🧑🏻💻
code step 01
Create a function to get transaction information from EtherScan. inside MetamaskValidationCommand.php
code step 02
At present we need to become pending transactions from database.
here we demand to add some delay to go transactions. because some time Etherium transactions may take more time to be a successful transaction. and so here we get transactions which are older than 20 minuets and condition = pending from database.
To call Transaction Model nosotros need call modal within our constructor.
Now we demand to create get function inside Transaction Model.
Then we tin create a function for validate transactions within MetamaskValidationCommand.php
Here we first get all the pending [older than 20min] transactions and loop them inside foreach.
then we go them 1 by one and transport transaction id (txHash) to EtherScan past using function which we mede above ( code step 01 ).
so our functions are ready to utilise.
Now we need to change our control with custom command params.
finally we need to add our command to kernel.php
app => Console => kernel.php
here I'k adding schedule to run command every Minuit. You lot are costless to alter for whatsoever time range --> References.
At present nosotros are ready to examination.
01 brand a transaction similar I described in Commodity 01.
02 Wait At to the lowest degree 20 Minuit (Yous may change the delay value within TransactionModel.php).
03 You tin see it's marked equally success. if its success payment.
I think your transaction also succeeded without an error. whatever error please comment beneath I will help you guys to success.
Important
In these both tutorials I accept described as very basic methods. we don't write codes like that in production sites. we need to retrieve more about security and durability. I guest you may got assist from my article.
You may Find my Fiver Gig Here.
https://world wide web.fiverr.com/s2/0c68721323
hither Yous may read commodity one
Here I'm Adding Public GitHub Repository which will store all of my tutorials. y'all may clone it and see every tutorials what I will publish 🤗.
GitHub Repository
Thank You Very much.
- Lathindu Pramuditha.
- GitHub Profile -> https://github.com/lathindu1
Source: https://dev.to/lathindu1/validate-metamask-transactions-with-etherscan-metamask-integration-with-laravel-part-2-25h6
0 Response to "How To Connect Metamask To Etherscan"
Post a Comment