1

I just finished syncing my Ethereum node. I'd like to set up a way my node can run a bash script or trigger something to run a PHP script every time someone interacts with a contract.

Node Detects transaction involving contract -> data sent to PHP script / recorded on my database -> website displays to users

How can I achieve something like this? Can someone give some pointers on where to start? Ethereum nodes are different than bitcoin nodes.

-1

First your node does not detect specific transaction, it just sync the blockchain and based on the configuration of your node, it computes transaction and update blockchain state, or simply sync.

To achieve what you want, you need to run a program watching interesting "events" related to your contract. If your process need to be fault tolerant, you need to store blocks already processed, to be able to restart your program and get potential old events.

Based on this, is PHP really important ? you decide based on your knowledge of nodejs / php and the purpose of the project.

PHP is not really important : You just want simple a task, or call to an URI with PHP right after. You can just adapt a simple example in nodejs with web3js, and do you want when an event occur.

nodejs > 
script + web3js >
simple task, or call to an external URL where your php script is executed

PHP is really important : you can use some implementation like this one https://github.com/digitaldonkey/ethereum-php and code the wanted behavior.

crontab >
php script (with a php implementation) >
request all events since last launch >
do processes >
store last watched block in db >
wait for next cron

In both scenarios, you need to connect to an ethereum node. It's where your node comes to play. But, you can also use public node, like infuria.io

Your node is just a "gateway" to the ethereum blockchain, nothing more, nothing less.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.