Transactions 以太坊eth_通过PHP curl发送事务
我正在尝试使用PHP curl发送以太坊事务 有许多其他呼叫成功,但这一个 代码片段:Transactions 以太坊eth_通过PHP curl发送事务,transactions,ethereum,json-rpc,Transactions,Ethereum,Json Rpc,我正在尝试使用PHP curl发送以太坊事务 有许多其他呼叫成功,但这一个 代码片段: $url = "http://127.0.0.1:9999"; $data = array( "jsonrpc" => "2.0", "method" => "eth_sendTransaction", "params" => array("from" => $f, "to
$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;
{"jsonrpc":"2.0","method":"eth_sendTransaction","params":{"from":"0x35fa3c7edd23b23bd714fd075d243097e14ed937", "to":"0xdab9a603ed3f1cf7b2b89f1cb1b57145e4828796","gas":"0x15f90","gasPrice":"0x430e23400","value":"0x9b6e64a8ec60000"},"id":"1"}
JSON编码数据:
$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;
{"jsonrpc":"2.0","method":"eth_sendTransaction","params":{"from":"0x35fa3c7edd23b23bd714fd075d243097e14ed937", "to":"0xdab9a603ed3f1cf7b2b89f1cb1b57145e4828796","gas":"0x15f90","gasPrice":"0x430e23400","value":"0x9b6e64a8ec60000"},"id":"1"}
未提交事务,日志中除了表单通知之外没有任何错误PHP通知:未定义属性:stdClass::$result in…
命令行:
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
以上工作完美
请指出我做错了什么?您的
params
字段缺少包装数组。试试这个:
"params" => array(array("from" => ...