0

I am trying to send some test ether on Rinkeby network using Infura, Im using some php library to make it.

<?php
use Web3p\EthereumTx\Transaction;
use Web3\Web3;

$valueSend = dechex(0.1 * 10**18);

$transaction = new Transaction([
  'nonce' => '0x'. dechex(282),
  'from' => '0xaDa4f3bB20A3658c1d25B6e687F5CF1b20e38BaA',
  'to' => '0xa73537dF8aECBE66240C2C53b748AF2F30FD2b71',
  'gas' => '0x76c0',
  'gasPrice' => '0x9184e72a000',
  'value' => '0x'.$valueSend,
  'chainId' => 4,
]);

// sign by private key
$signedTransaction = $transaction->sign('<PRIVATE_KEY>');

// Call Function
$createTransaction = json_decode(loadCURL('0x'.$signedTransaction, 'eth_sendRawTransaction'));
$getTransaction = json_decode(loadCURL($createTransaction->result, 'eth_getTransactionReceipt'));


/***************************/
function loadCURL($txKey, $method){
    $url = 'https://rinkeby.infura.io/v3/461ae29f1e0f4509bbe4fe9bf0440fd4';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    $data = array(
        'jsonrpc' => '2.0',
        'method' => $method,
        'params' => [$txKey],
        'id' => 4,
    );
    $payload = json_encode($data);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);

    if(curl_errno($ch)){
        throw new Exception(curl_error($ch));
    }

    return $response;
}

result: eth_sendRawTransaction

{
    "jsonrpc": "2.0",
    "id": 4,
    "result": "0x952f8831051cb7febe93d7409afc470a00953e0eece686a1be120afb4d43401f"
}

result: eth_getTransactionReceipt

{
    "jsonrpc": "2.0",
    "id": 4,
    "result": null
}

and I cant check on https://rinkeby.etherscan.io/tx/<Transaction_Hask> https://rinkeby.etherscan.io/tx/$createTransaction->result

Please let me know problem in my code, I want use PHP to create transaction and can check address info.

Your Answer

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

Browse other questions tagged or ask your own question.