Skip to content

Instantly share code, notes, and snippets.

@askaaqib
Created December 7, 2020 11:24
Show Gist options
  • Select an option

  • Save askaaqib/5babe2a5affa9fb3e5257991dcaf2973 to your computer and use it in GitHub Desktop.

Select an option

Save askaaqib/5babe2a5affa9fb3e5257991dcaf2973 to your computer and use it in GitHub Desktop.

Revisions

  1. askaaqib created this gist Dec 7, 2020.
    53 changes: 53 additions & 0 deletions ethereum-transaction.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    //Eth Setup
    $eth = new \FurqanSiddiqui\Ethereum\Ethereum();
    $eth->networkConfig()->setChainId(42);

    //Sender Private Key
    $prv = $eth->keyPairs()->privateKeyFromEntropy(hash("sha256", "AlphaPackCrew"));



    //Infura Setup
    $proejctId = "b14c61a14f884a6183736967b070bb7d";
    $projectScope = "71ca362e570a42cf9b2540ac3a2a44b9";
    $infura = new \FurqanSiddiqui\Ethereum\RPC\InfuraAPI($eth, $proejctId, $projectScope, "kovan");

    $gasPrice = $infura->eth_gasPrice();

    $tx = new \FurqanSiddiqui\Ethereum\Transactions\TxBuilder($eth);
    $to = new \FurqanSiddiqui\Ethereum\Accounts\Account($eth, "0x13435FB43DA04ef0D32f5d1e5E84a024adf6aE2E");
    $tx->to($to);
    $gasPrice = new \FurqanSiddiqui\Ethereum\Math\WEIValue($gasPrice);
    $nonce = $infura->eth_getTransactionCount($prv->publicKey()->getAccountAddress());

    $tx->gas($gasPrice, 25000);
    //$tx->data($data);
    $amount = new \FurqanSiddiqui\Ethereum\Math\WEIValue(1);
    $tx->value($amount);
    $tx->nonce($nonce);

    echo "<pre>";
    print_r($tx);
    echo "<br>";

    $serializedTx = $tx->serialize();
    echo "<br>";
    echo "Serialzed";
    echo "<br>";

    print_r($serializedTx);


    echo("Sign Transaction: ");
    echo "<br>";
    $signedTx = $prv->signTransaction($serializedTx);

    echo "<br>";
    $transactionData = $signedTx->serialized()->hexits(true);
    //print_r($signedTx->serialized()->hexits(true));

    $response = $infura->eth_sendRawTransaction($transactionData);

    echo "Transaction Hash Hex:";
    print_r($response);
    die();