这一整天都在做我的头,在费力地完成并设法将所有的值转换为十六进制之后,我使用来自GitHub的web3p/ ethereum库创建并签署了ethereum事务。我将带有参数的cUrl请求输入到infura。我得到了一个事务散列的响应,但是当我在以太扫描和其他搜索中搜索它时,它没有出现,有什么想法我做错了吗?
use Web3\Web3;
use Web3p\EthereumTx\Transaction;
$balance = bcdiv($balanceInWei, "1000000000000000000", 18);
$gasTotal = 4000000000 * 21004;
$value = bcsub($balanceInWei, $gasTotal);
$gas = dechex(21004);
$gasPrice = dechex(4000000000);
function bcdechex($dec) {
$hex = '';
do {
$last = bcmod($dec, 16);
$hex = dechex($last).$hex;
$dec = bcdiv(bcsub($dec, $last), 16);
} while($dec>0);
return $hex;
}
$hexValue = bcdechex($value);
$nonce = time();
$hexNonce = dechex($nonce);
echo $wallet_address;
// with chainId
$transaction = new Transaction([
'nonce' => '0x'.$hexNonce,
'from' => $wallet_address,
'to' => '0xMyWalletAddress',
'gas' => '0x'.$gas,
'gasPrice' => '0x'.$gasPrice,
'value' => '0x'.$hexValue,
'chainId' => 1,
'data' => '0x0'
]);
$signedTransaction = $transaction->sign($databaseContainer->private_key);
$url = "https://mainnet.infura.io/v3/MyApiKey";
$data = array(
"jsonrpc" => "2.0",
"method" => "eth_sendRawTransaction",
"params" => array("0x".$signedTransaction),
"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);
dd($result);dd只是我把结果扔到了大桶里。提前谢谢。
发布于 2018-12-23 21:08:01
看起来,您正在使用十六进制编码的当前时间作为事务的当前时间。这不是正确的期望值;您需要确保您使用的是正确的预期帐户。您可以通过调用eth_getTransactionCount获得这个当前值。
还请注意,您正在接收的是事务散列,而不是收据。事务哈希指示您的事务已发送到网络。事务收据是成功挖掘/验证事务的指示器。
https://stackoverflow.com/questions/53905585
复制相似问题