正在尝试使用PHP curl函数发送事务。但是在消息:非数组参数时出现错误。传递的参数是from,to,value(amount * 10 ^ 18)另外我想知道数据字段很重要吗?如果是,我该如何创建它。
是否缺少其他任何参数?请帮助我解决这个问题。
function eth_sendTransaction($from_address,$to,$amount)
{
$data = array();
$data['jsonrpc'] = $this->version;
$data['id'] = $this->id++;
$data['method'] = 'eth_sendTransaction';
$transaction = array('from'=>$from_address,'to'=>$to,'value'=>(float)$amount);
$data['params'] = $transaction;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->wallet_ip);
curl_setopt($ch, CURLOPT_PORT, $this->wallet_port);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, count($transaction));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$ret = curl_exec($ch);
curl_close($ch);
print_r($ret);
}