Closed danirabbani90 closed 5 years ago
Hi @danirabbani90, would you like to post code here (please do not include sensitive information)?
$transaction = new Transaction([
'nonce' => '0xd',
'from' => "0xF728f02b81DfE880A6CD8748893c94925d70a8B6",
'to' => '0x68484CF447d6E2eA8AF27d2b1DfE9b8DC5d24DB3',
'gas' => '0x1',
'gasPrice' => '0xee6b2800',
'value' => '0x38d7ea4c68000',
'chainId' => 1
]);
$serialize=$transaction->serialize();
$signedTransaction = $transaction->sign("PrivateKey");
$getFromAddress=$transaction->getFromAddress();
$web3 = new Web3(JSONRPC_HOST);
$eth=$web3->eth;
$eth->sendRawTransaction('0x'.$signedTransaction, function ($err, $transaction) use ($eth) {
if ($err !== null) {
echo 'Error: ' . $err->getMessage();
return;
}
echo 'Tx hash: ' . $transaction . PHP_EOL;
$eth->getTransactionByHash($transaction, function ($err, $res) use ($eth) {
if ($err !== null) {
var_dump($err->getMessage());
return;
}
dump($res);
//0xcff87fe6c618a7cce954701c954a9c701d981f3b1bcab6c9e931b7fc159a9afa
});
//0xcff87fe6c618a7cce954701c954a9c701d981f3b1bcab6c9e931b7fc159a9afa
});
$transaction = new Transaction([ 'nonce' => '0xd', 'from' => "0xF728f02b81DfE880A6CD8748893c94925d70a8B6", 'to' => '0x68484CF447d6E2eA8AF27d2b1DfE9b8DC5d24DB3', 'gas' => '0x1', 'gasPrice' => '0xee6b2800', 'value' => '0x38d7ea4c68000', 'chainId' => 1 ]); $serialize=$transaction->serialize(); $signedTransaction = $transaction->sign("PrivateKey"); $getFromAddress=$transaction->getFromAddress(); $web3 = new Web3(JSONRPC_HOST); $eth=$web3->eth; $eth->sendRawTransaction('0x'.$signedTransaction, function ($err, $transaction) use ($eth) { if ($err !== null) { echo 'Error: ' . $err->getMessage(); return; } echo 'Tx hash: ' . $transaction . PHP_EOL; $eth->getTransactionByHash($transaction, function ($err, $res) use ($eth) { if ($err !== null) { var_dump($err->getMessage()); return; } dump($res); //0xcff87fe6c618a7cce954701c954a9c701d981f3b1bcab6c9e931b7fc159a9afa }); //0xcff87fe6c618a7cce954701c954a9c701d981f3b1bcab6c9e931b7fc159a9afa });
换了一个公共节点,就可以了,之前用的nodesmith.io,改成infura.io的就可以了
@huigan because your transaction wasn't included in the block, you got the null when search the transaction hash. You might need to check the gas or gasPrice.
hi there i have just followed the steps you wrote for sending ethereum transaction but unfortunately in the log the ethereum txdata is always null that is why it is unable to sign transactions ?