我用我的私钥签署了一个事务,然后使用sendRawTransaction函数在网络上发送事务,我得到了事务哈希,但是当我在getTransactionByHash中使用这个事务时,我得到了空块哈希、响应中的块号和从未挖掘的事务。
我正在使用web3-php库并在laravel中实现它。请帮助解决这个问题。提前谢谢你的帮助。
使用的库:https://github.com/web3p/web3.php https://github.com/web3p/ethereum-tx
这是我的密码。
$toAddress = '0x551f7DaFb0569....';
$fromAccount = $this->getOwnerAddress();
$from_addr_nonce = "";
$contract = $this->getDeployedContract();
$eth = $this->getEthObject();
$eth->getTransactionCount($this->getOwnerAddress(),function($err,$data) use (&$from_addr_nonce){
$from_addr_nonce = gmp_intval($data->value);
});
$from_addr_nonce = Utils::toHex($from_addr_nonce,true);
$data = "0x".$contract->getData('safeMint', $toAddress, $metadataHash);
$gasPrice = Utils::toHex(1000);
$gas = 10e6;
$txParams = [
'from' => $fromAccount,
'to' => $this->contractAddress,
'value' => "0x0",
'nonce' => $from_addr_nonce,
'gas' => Utils::toHex($gas,true),
'gasPrice' => $gasPrice,
'chainId' => 4,
'data' => $data,
];
$transaction = new Transaction($txParams);
$signedTransaction = $transaction->sign($this->getprivateKey());
$eth->sendRawTransaction("0x".$signedTransaction, function ($err, $tx) use (&$nftAddress) {
if ($err !== null) {
echo "Error: ".$err->getMessage();
exit();
}
$nftAddress = $tx;
});发布于 2021-11-26 09:30:58
这是事务库的一个问题:https://github.com/web3p/ethereum-tx。改为使用以下库。https://github.com/kornrunner/php-ethereum-offline-raw-tx
我现在很好用。
https://ethereum.stackexchange.com/questions/114265
复制相似问题