1

In my case, i have an API written in PHP which periodically checks the database. If certain condition was met, i need to send an alert message from the API to an account/node in the Ethereum blockchain network through smart contract. Any idea how can this be done? or is this even possible?

PS: I am using Apache web server with MYSQL database

  • Something doesn't sound quite right in your description - "send message from the API to an account/node though a smart contract". First of all, I take it that by API you mean an off-chain client (implemented in PHP in your case). Now, the flow is usually that you send a message (transaction) from the off-chain client through a node to a smart contract. In order to send it, you need to use an account which holds enough ether. So in short, PHP client --> sign message with account's private key --> node --> smart contract. – goodvibration Dec 25 '18 at 15:34
  • Or less recommended: unlock the account on the node (using the account's private key), and then, PHP client --> send message to node --> sign message and send to smart contract. – goodvibration Dec 25 '18 at 15:36
  • But in any case, you do not use the smart contract in order to send a message to an account or a node. – goodvibration Dec 25 '18 at 15:37
  • Oh i see, but how to implement the "PHP client--> sign message with account's private key " part? Do you have any example code? – Sienz Pz Dec 25 '18 at 15:43
  • In Javascript (via web3.js), not in PHP. – goodvibration Dec 25 '18 at 16:32
0

You can use a client library for PHP (Such as : https://github.com/sc0Vu/web3.php ) to interact with Ethereum.

Example of calling a contract from PHP:

$contract = new Contract('http://localhost:8545', $abi);
// estimate function gas
$contract->at($contractAddress)->estimateGas($functionName, $params, $callback);
// change function state
$contract->at($contractAddress)->send($functionName, $params, $callback);
  • I thought ethereum-php is able to read-only? – Sienz Pz Dec 26 '18 at 7:18
  • Yes, answer has been updated to use a different library. – Shamit Verma Dec 28 '18 at 1:29

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.