The monitoring of the Ethereum address for operations confirmation php
You will have to use [Ethers.js] ( to monitor the Ethereum address and follow the number of surgical confirmations, which provides a simple way to communicate Ethereum Chain. In this article, we will investigate how to achieve this goal using PHP.
Ethers.js PHP setting
Install the Ethers.js package first worldwide using composers:
`Bash
The composer requires Etere-Js
`
So create a new php file (EGEthereum_monitor.php) and add the following code:
PHP
Use Etere \ wallet;
Use Ether \ Protars \ Httpprovider;
Use Ether \ Protars \ WebsocketPrier;
Class Ethereummonitor {
Private $ walletaddress;
Private $ providerurl;
Public function __Construct ($ walletaddress, $ providerurl) {
$ This-> walletdress = $ wathettaddrest;
;
}
Public function of Getchainid () {
// Ethers.js automatically sets the ID circuit on 1
Return 1;
}
WatiforenceConfirmation ($ address, $) {
In the meantime (true) {
Attempt {
// Check that we have a valid cash copy
$ Wallet = new wallet ($ this-> walletaddress);
// Get the operating object using web3.js
$ tx = $ wallet-> operation ($ address, $ sum);
// Get the leaflet of the operation and the temporal tag
$ Hash = $ tx-> hash;
$ Time Mark = $ TX-> Time tag;
// Check the confirmation of surgery
If ($ tx-> confirmation> 0) {
return the truth; // the operation has at least approval
} OTHER {
// If the approval is not found, wait and try again
The Eco operation with $ address address has not reached confirmation:. Json_encode ($ hash). "\ N";
sleep (1); // wait 1 second before checking again
}
} To capture (exception $ e) {
Eco's error occurred pending confirmation of the operation:. $ e-> GetMessage (). "\ N";
break;
}
}
return the wrong; // The operation has not reached any approval
}
}
// Example of use:
$ Walletaddress = '0x1234567890Abcdef';
$ Providerrl = '
$ Monitor = New Ethereummonitor ($ walletaddress, $ providerurl);
Confirmation of the Eco operation:. ($ Monitor-> Getchainid () == 1? 'Yes': 'No'). "\ N";
`
In this example, we create an example of the Etherummonitor class with our wallet address and the supplier’s URL. So we use some time to check the operations of the operations every second using the WatitransctionConfirfignation method method.
How it works
- The Eteter.js bookcase automatically sets the ID circuit 1.
2
- We receive a bag of operation and time from the object of the operation.
4 Otherwise, we wait and play for 1 second.
Remember that this implementation presupposes that you have an influence project with your URL of the Ethereum network supplier. In the official documentation, you can find more information on how to start using Ethers.js and Web3.js: <
Leave a Reply