In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
How to use EthMon.php to monitor Ethernet Square token transfer transactions, I believe that many inexperienced people are at a loss about this. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
The EthMon development package is used to monitor the transfer transactions of ERC20 token contracts in Ethernet Square.
1. Overview of the development package
The features of the EthMon token transaction monitoring package are as follows:
Monitor token transfer / transfer transactions at the specified address in the ethersquare contract log
Customize the business logic when a token transaction occurs
Both standard Web3 interfaces (such as Infura) and Etherscan non-standard interfaces are supported
EthMon runs in the PHP 7.1 + environment, and the main classes and their relationships are shown in the following figure:
For a list of the main code files of EthMon, please see the official description: http://sc.hubwiz.com/codebag/ethmon-php/
2. Instructions for use
Before you begin, replace the contents of the following files with your own API KEY
Demo/etherscan-key
Demo/infura-key
EthMon is the entry class of the development package. Call its scanBlocks () method to scan the Ethernet Square block in the specified area, extract and parse the contract log. After matching the listening address, call the handleEvent () method of the event listener (IEventListener API implementation object) and pass in the parsed event object.
2.1 IEventListener
The caller's program needs to encapsulate its own business logic in the implementation class of the IeventListener interface, such as writing to a database, and so on. The following code implements a basic event listener-- simply displays the contents of the output event object on the screen:
Class EzListener implements IEventListener {function handleEvent ($event) {var_dump ($event);}}
The argument to the handleEvent () method is a StdClass object, which is structured as follows:
Block: exchange in block number
Txhash: transaction hash
Contract: the address of the contract that triggered the event
Name: event name, for example: Transfer
Flow: capital flow. Possible values: inbound-in, outbound-transfer out
Params: an array of event parameters, with the following members:
Transfer address, string
Transfer address, string
The number of tokens, BigInteger, can be converted to a string by calling the toString () method
Once you have defined the event listener, you can set up and start the listener as follows:
2.2 create an EthMon object
To create an EthMon instance, you need to pass in an EthApi object, such as using the EthApiWeb3 object:
$ethApi = new EthApiWeb3 ('https://mainnet.infura.io/v3/');$em = new EthMon ($ethApi); 2.3 set the token contract to listen for
After creating an EthMon instance, you need to call the watchToken () method to set the token contract to listen for, such as listening on the BNB token contract:
$em- > watchToken ('0xb8c77482e45f1f44de1745f52c74426c631bdd52'); 2.4 add addresses related to token transactions to be monitored
Use the watchAddress () method of the EthMon instance to add the address related to the token transaction to listen for. For example, the following code listens for the event that the address 0xd3705916ce7e2c43806e0e0707c4b9d6f27e9ab2 receives a token:
$em- > watchAddress ('0xd3705916ce7e2c43806e0e0707c4b9d6f27e9ab2)
The following code listens for the event of the address 0x6c6cbbb3ef3d690de7aa0525b5e6c2ffe7aed6a5 transferring out the token:
$em- > watchAddress ('0x6c6cbbb3ef3d690de7aa0525b5e6c2ffe7aed6a5examples)
Use the EthMon::FLOW_INOUT flag when you want to listen for transfer-in / transfer-out token events for an address:
$em- > watchAddress ('0xd3705916ce7e2c43806e0e0e0707c4b9d6f27e9ab2); add event listeners
Call the addEventListener () method of the EthMon instance to add an event listener object that will be called when the condition is met when EthMon's scanBlocks () scans the block.
For example, the following code adds an instance object of the EzListener class we defined earlier:
$em- > addEventListener (new EzListener); 2.6 scan block chain
The scanBlocks () method of EthMon needs to be called periodically to scan the blockchain to track the new token transaction log. The two parameters of scanBlocks () are used to specify the starting and ending chunk number of the scan, respectively. When a special latest string is used, the latest chunk is used.
For example, the following code scans the latest block every 5 seconds:
While (true) {$em- > scanBlocks ('latest','latest'); sleep (5);}
Although any integer value can be used for both start and end chunk numbers, it is not recommended to scan multiple chunks at a time due to the limited number of records returned by Etherscan and Web3. For example, the following code attempts to scan 405 blocks from 8500000 to 8500404:
$em- > scanBlocks (8500000pr 8500404); / / not recommended, it may fail
Block-by-block scanning is recommended, and appropriate delay processing is carried out during the two scans, taking into account the access frequency restrictions of third-party services.
After reading the above, have you mastered how to use EthMon.php to monitor Ethernet Square token transfer transactions? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.