0

I've signed a transaction with my private key and then used the sendRawTransaction function to send the transaction on the network, I got the Transaction Hash, but when I use that transaction has in getTransactionByHash I got empty block hash, block number in the response and transaction never mined.

I'm using web3-php library and implementing it in laravel. Please help to solve this issue. Thanks in advance for your help.

Libraries used: https://github.com/web3p/web3.php https://github.com/web3p/ethereum-tx

Here is my code.

                $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;
                });
1
0

This is an issue with the transaction library:
https://github.com/web3p/ethereum-tx.

Use the following library instead.
https://github.com/kornrunner/php-ethereum-offline-raw-tx

It's working fine with me now.

1
  • How do you sign the transaction with php-ethereum-offline-raw-tx?
    – Vincent
    Dec 29 '21 at 5:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.