{"id":15384452,"url":"https://github.com/digitaldonkey/ethereum-php-eventlistener","last_synced_at":"2025-04-15T17:33:54.895Z","repository":{"id":138705106,"uuid":"143413214","full_name":"digitaldonkey/ethereum-php-eventlistener","owner":"digitaldonkey","description":"Process Ethereum Blockchain data with PHP or continuously react on latest Blocks or contract Events ","archived":false,"fork":false,"pushed_at":"2018-08-09T15:09:50.000Z","size":21,"stargazers_count":20,"open_issues_count":2,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-01T11:34:41.297Z","etag":null,"topics":["ethereum","ethereum-events","ethereum-php","event-processor","eventlistener","php","smart-contract"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/digitaldonkey.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-03T10:21:59.000Z","updated_at":"2023-10-30T10:51:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"9efe35ec-4eeb-4811-8ba3-0c7abfb506fd","html_url":"https://github.com/digitaldonkey/ethereum-php-eventlistener","commit_stats":{"total_commits":2,"total_committers":1,"mean_commits":2.0,"dds":0.0,"last_synced_commit":"a434ebc2cc44f26d0a519d33c36cd0fac0be9483"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitaldonkey%2Fethereum-php-eventlistener","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitaldonkey%2Fethereum-php-eventlistener/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitaldonkey%2Fethereum-php-eventlistener/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitaldonkey%2Fethereum-php-eventlistener/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/digitaldonkey","download_url":"https://codeload.github.com/digitaldonkey/ethereum-php-eventlistener/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223681406,"owners_count":17184945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ethereum","ethereum-events","ethereum-php","event-processor","eventlistener","php","smart-contract"],"created_at":"2024-10-01T14:42:00.741Z","updated_at":"2024-11-08T12:02:35.770Z","avatar_url":"https://github.com/digitaldonkey.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ethereum-php Listener and Indexer\n\n**TL;DR**\n\nWhen developing dapps you might need some Backend process to react data of the latest block or on on-chain Events (Solidity Events). You might fill up some database by indexing all blocks or set up a daemon process to do something every time a new Block is created. \n\n--------------------------------\n\nAs much as we want real decentralization, the reality is actually different. \nMots Dapp's require a Backend process. Sometimes for additional data which is too expensive to store (semi decentralized apps) or at least for monitoring what is happening at on chain.\n\n\nYou can do this in PHP very easily. E.g Indexing a chain from block 0 to the latest at script start time:\n\n```php\n$web3 = new Ethereum('http://192.168.99.100:8545');\n// Block 0 -\u003e last block.\nnew BlockProcessor($web3, function (Block $block) {\n\n    // This will be run on every Block.\n    print \"\\n\\n#### BLOCK NUMBER \" . $block-\u003enumber-\u003eval() . \" ####\\n\";\n\n    // Add to database... \n    print_r($block-\u003etoArray());\n  }\n);\n\n``` \n\nRun the script. E.g: \n\n```bash \nphp app/basic-blockProcessor-example.php\n```\n\nYou need to run `composer install` in the app directory to load the dependencies.\n\n## Integration with Truffle and Contract Events\n\nIf you are using [Truffle](http://truffleframework.com/) to develop you Dapp you can easily set up a monitoring system for your smart contracts:\n\n```php \n// Extend a \\Ethereum\\SmartContract with EventHandlers\nclass CallableEvents extends SmartContract {\n  public function onCalledTrigger1 (EthEvent $event) {\n    echo '### ' . substr(__FUNCTION__, 2) . \"(\\Ethereum\\EmittedEvent)\\n\";\n    var_dump($event);\n  }\n  public function onCalledTrigger2 (EthEvent $event) {\n    echo '### ' . substr(__FUNCTION__, 2) . \"(\\Ethereum\\EmittedEvent)\\n\";\n    var_dump($event);\n  }\n}\n\n$web3 = new Ethereum('http://192.168.99.100:8545');\n$networkId = '5777';\n\n// Contract Classes must have same name as the solidity classes for this to work.\n$contracts = SmartContract::createFromTruffleBuildDirectory(\n  'YOUR/truffle/build/contracts',\n   $web3,\n   $networkId\n);\n\n// process any Transaction from current Block to the future.\nnew ContractEventProcessor(\n  $web3,\n  $contracts,\n  'latest',\n  'latest'\n);\n\n```\n\n## Background \n\nThe Loop script is based on [reactphp](https://github.com/reactphp/react) which is actually older that Javascript React. \n\nThe Ethereum part is based on [Ethereum-php](https://github.com/digitaldonkey/ethereum-php) library.\n\nYou might use [ganache-cli-docker-compose](https://github.com/digitaldonkey/ganache-cli-docker-compose) for testing.\n\nYou may use the indexer with [Infura](https://infura.io) Ethereum as a Service, as it doesn't rely on filters, which Infura does not support.\n\nI used a very simple [DAPP](https://github.com/digitaldonkey/react-box-event-handling) to interact with the CallableEvents smart contract used as a example here. \n\n\n##Docker\n\n```bash \n# Build\ndocker build -t ethereum-php-event-handler .\n\n# Login\ndocker run -v $(pwd)/app:/opt/local/php-ethereum-listener -it ethereum-php-event-handler bash\n\n# Deamon \ndocker run -v $(pwd)/app:/opt/local/php-ethereum-listener -it ethereum-php-event-handler bash -c '/opt/local/bin/docker-run.sh'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitaldonkey%2Fethereum-php-eventlistener","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdigitaldonkey%2Fethereum-php-eventlistener","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitaldonkey%2Fethereum-php-eventlistener/lists"}