ethereum eth sendTransaction via PHP curl

0 votes

I am trying to send ethereum transaction using PHP curl

There are number of other calls which are successful but this one...

Code snippet:

$url = "http://127.0.0.1:9999";

        $data = array(
                "jsonrpc" => "2.0",
                "method" => "eth_sendTransaction",
                "params" => array("from" => $f, "to" => $t, "gas" => $gv, "gasPrice" => $gp, "value" => $value),
                "id" => "1"
        );

        $json_encoded_data = json_encode($data);

        var_dump($json_encoded_data);

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $json_encoded_data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json',
                'Content-Length: ' . strlen($json_encoded_data))
        );

        $result = json_decode(curl_exec($ch));
        curl_close($ch);

        $parsed = $result->result;

        return $parsed;

JSON encoded data:

{"jsonrpc":"2.0","method":"eth_sendTransaction","params":{"from":"0x35fa3c7edd23b23bd714fd075d243097e14ed937", "to":"0xdab9a603ed3f1cf7b2b89f1cb1b57145e4828796","gas":"0x15f90","gasPrice":"0x430e23400","value":"0x9b6e64a8ec60000"},"id":"1"}

Transactions are not getting submitted and there is no error apart form Notice in the logs PHP Notice: Undefined property: stdClass::$result in...

Command line:

curl -H "Content-type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_sendTransaction","params":[{"from":"0x35fa3c7edd23b23bd714fd075d243097e14ed937","to":"0xdab9a603ed3f1cf7b2b89f1cb1b57145e4828796","gas":"0x15f90","gasPrice":"0x430e23400","value":"0x9b6e64a8ec60000"}],"id":"1"}' http://localhost:9999

Above works perfectly...

Can one please point out what am I doing wrong ?

Sep 27, 2018 in Blockchain by digger
• 26,740 points
4,965 views

1 answer to this question.

0 votes

Your params field is missing a wrapping array. Try this:

"params" => array(array("from" => ...
answered Sep 27, 2018 by slayer
• 29,370 points

Related Questions In Blockchain

0 votes
1 answer

Curl Script Usage in Ethereum Blockcypher's API

You should store and keep the private ...READ MORE

answered May 28, 2018 in Blockchain by Christine
• 15,790 points
1,449 views
0 votes
1 answer

PHP IPC with geth Ethereum: How to communicate with client?

You have to use PHP Sockets $sock = socket_create(AF_UNIX, ...READ MORE

answered Oct 22, 2018 in Blockchain by Omkar
• 69,220 points
1,803 views
0 votes
0 answers

Attach two nodes on different machine via private blockchain (Ethereum)

I have seen many blogs regarding ways ...READ MORE

Jun 9, 2020 in Blockchain by Ritvik
• 120 points
1,545 views
0 votes
1 answer

How to make sure transactions take no fee in a private Ethereum blockchain?

In a private ethereum network you have ...READ MORE

answered Mar 26, 2018 in Blockchain by Christine
• 15,790 points

edited Mar 26, 2018 by Christine 1,594 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,947 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,471 views
+3 votes
2 answers

How to run ethereumjs using Node.JS

You need to install testrpc globally on ...READ MORE

answered Mar 27, 2018 in Blockchain by ned_crew
• 1,610 points
1,467 views
0 votes
1 answer

Php code to generate Ethereum wallets.

You can use web3.eth.accounts in web3js web3.eth.accounts.create(); With Php, ...READ MORE

answered Jul 27, 2018 in Blockchain by slayer
• 29,370 points
3,396 views
0 votes
1 answer

How to monitor Ethereum private network?

geth should be started with --metrics. try the ...READ MORE

answered Jul 11, 2018 in Blockchain by slayer
• 29,370 points
1,557 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP