I wish to have a PHP script use Infura's endpoint to call eth_sendRawTransaction. I have a PHP script which uses curl to call functions through Infura's endpoint, like eth_getBalance.

I use BlockCypher's "signer" program to sign data at BlockCypher.

The following description of eth_sendRawTransaction does not indicate how to create the signed transaction data, here.

Please provide a snippet of PHP code which exemplifies how to create the signed transaction data. At the place where the data needs to be signed, just use this line of code:

$sSignature = exec("./signer $sToSign $sPrivateKey");

I'm sure many other people will benefit from this example.

  • 1
    did you find any solution for it? – Yogesh Karodiya Nov 7 '17 at 6:54

Consider looking into one of the PHP libraries that is a wrapper for the JSON-RPC.

PHP Library for Ethereum

| improve this answer | |
  • I see you are the founder of Infura. Why is this so elusive? Where is this documented? Neither of those PHP libraries answered my question, and those projects are not even maintained anymore. I need to know specifically how to use PHP to create the signed transaction data: What JSON fields needs to be sent, when does which data need to be signed and hex-encoded, etc.. Please provide a specific PHP example that has been tested. I want to use Infura and Ehtereum, but this very basic issue (sending a transaction) is not properly documented anywhere. – Tester Sep 20 '17 at 14:33
  • 1
    It's possible that nobody has written a library to sign raw transactions in PHP, as for various reasons PHP isn't a common choice for apps that need high security, which you may well do if you handle cryptographic keys. If you want to write one, see this answer for some non-PHP implementations: ethereum.stackexchange.com/questions/3386/… In particular the python implementation is probably quite easy to read and understand. – Edmund Edgar Sep 20 '17 at 21:19
  • 1
    I'm not looking for a library, just a precise explanation via a tested PHP code sample that shows what JSON fields needs to be sent, when does which data need to be signed and hex-encoded, etc. I posted this question on three websites, and it appears no one knows the answer, so that leaves serious doubts about using Infura to add transactions to Ethereum. – Tester Sep 20 '17 at 21:27
  • On the website that you recommended, each example uses different names for the JSON fields that need to be submitted. I need to know the names of the JSON fields that should be submitted to Infura. Those examples also use external libraries, so I can't see the exact instructions for the entire process. – Tester Sep 20 '17 at 21:43
  • 1
    I'm very disappointed that this post did not receive a reply containing what I requested (a PHP example), and that the following two posts received no replies whatsoever: github.com/INFURA/infura/issues/33 reddit.com/r/infura – Tester Sep 20 '17 at 21:47

You should use web3.js

I love PHP but it really suck with geth, geth itself hard and documentation sporadic and peoples know fews. I really got stuck building my whole app on php (generate wallet on register) then integrate web3.js in. Better you use only JS, a good example of a fabulous code is myetherwallet

From official web3.js doc:


var Tx = require('ethereumjs-tx');
var privateKey = new Buffer('e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex')

var rawTx = {
  nonce: '0x00',
  gasPrice: '0x09184e72a000', 
  gasLimit: '0x2710',
  to: '0x0000000000000000000000000000000000000000', 
  value: '0x00', 
  data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057'

var tx = new Tx(rawTx);

var serializedTx = tx.serialize();


web3.eth.sendRawTransaction('0x' + serializedTx.toString('hex'), function(err, hash) {
  if (!err)
    console.log(hash); // "0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385"
| improve this answer | |

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.