Created
December 7, 2020 11:24
-
-
Save askaaqib/5babe2a5affa9fb3e5257991dcaf2973 to your computer and use it in GitHub Desktop.
Ethereum Transaction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment