banner



How To Connect Metamask To Etherscan

Cover image for Metamask Integration With Laravel Part 2[ Validate Transactions With EtherScan ]

Lathindu Pramduitha

Metamask Integration With Laravel Office two[ Validate Transactions With EtherScan ]

Screenshot 2021-02-17 at 01.24.06

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.

Screenshot 2021-02-17 at 00.01.47

At present we need to create API key
step 01

Screenshot 2021-02-17 at 00.04.37

footstep 02

Screenshot 2021-02-17 at 00.06.18

stride 03

Screenshot 2021-02-17 at 00.07.27

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.

Screenshot 2021-02-16 at 23.21.27

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

Screenshot 2021-02-16 at 23.22.33

How To Validate?

For validate a transaction we tin can apply EtherScan 'southward Free API.

Screenshot 2021-02-17 at 00.22.38

You tin come across number of methods in EtherScan API.

Screenshot 2021-02-17 at 00.24.09

Here we use eth_getTransactionByHash method only.

Screenshot 2021-02-17 at 00.27.53

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

Screenshot 2021-02-17 at 00.38.27

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.

Screenshot 2021-02-17 at 00.42.36

Now we demand to create get function inside Transaction Model.

Screenshot 2021-02-17 at 00.47.43

Then we tin create a function for validate transactions within MetamaskValidationCommand.php

Screenshot 2021-02-17 at 00.51.45

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.

Screenshot 2021-02-17 at 00.58.02

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.

Screenshot 2021-02-17 at 01.02.23

At present nosotros are ready to examination.

01 brand a transaction similar I described in Commodity 01.

Screenshot 2021-02-17 at 01.16.27

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.

Screenshot 2021-02-17 at 01.19.17

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

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel