1

This has been doing my head in all day, after wading through and managing to get all my values converted to hex I create and sign the ethereum transaction using the web3p/ethereum-tx library from GitHub. I put in the cUrl request with the parameters to the infura mainet. I get a response with a transaction hash but when I search for it on etherscan and others it does not show up, any ideas what I'm doing wrong?

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 is just me dumping the result in larvel. Thanks in advance.

1
  • Same here, any thoughts !! Any thoughts, transaction hash not show up in etherscan.io, for verification ?? Nov 3 '20 at 15:08
1

It looks to me that your nonce is not right. Nonce should be an incrementing transaction counter, not derives from unixtimestamp. Also it seems you are missing gasLimit parameter?

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.