Skip to content

Instantly share code, notes, and snippets.

@askaaqib
Last active November 2, 2020 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save askaaqib/ec04f6b92c915ada4af1de5cb54bc838 to your computer and use it in GitHub Desktop.
Save askaaqib/ec04f6b92c915ada4af1de5cb54bc838 to your computer and use it in GitHub Desktop.
Ethereum Testing
<?php
require "../vendor/autoload.php";
$eth = new \FurqanSiddiqui\Ethereum\Ethereum();
echo "<pre>";
//// CREATE PRIVATE KEY
//$prv = $eth->keyPairs()->privateKeyFromEntropy(hash("sha256", "whocares1"));
//$prv1 = $eth->keyPairs()->privateKeyFromEntropy(hash("sha256", "whocares2"));
//
//
//echo "<h3>Private Key 1</h3>";
//var_dump($prv->base16()->value());
//
//echo "<h3>Private Key 2</h3>";
//var_dump($prv1->base16()->value());
//
////echo "<h3>Get Public Key From Private Key</h3>";
//$pub = $prv->publicKey();
//$pub1 = $prv1->publicKey();
////var_dump($prv->publicKey());
//
//echo "<h3>Get Address From Public Key 1 </h3>";
//$address = $pub->getAccount()->getAddress();
//var_dump($address);
//
//echo "<h3>Get Address From Public Key 2 </h3>";
//$address1 = $pub1->getAccount()->getAddress();
//var_dump($address1);
//Infura
$proejctId = "2ab0996559544efca0d85f4135b22322";
$projectScope = "fcab5f5e357c410bbfdb82b6c7058598";
$infura = new \FurqanSiddiqui\Ethereum\RPC\InfuraAPI($eth, $proejctId, $projectScope, "ropsten");
//// GET ACCOUNT BALANCE
//$bal = $infura->eth_getBalance("0x137e98519f21F4bb4fFa9598a47eD6BaB92215B3");
//echo "<h3>Get Account Balance</h3>";
//var_dump($bal);
//
//// GET ACCOUNT BALANCE
//$blockNo = $infura->call("eth_blockNumber", []);
//echo "<h3>Get Block Number</h3>";
//var_dump($blockNo);
//
//// GET CHAIN ID
//$chainId = $infura->call("eth_chainId", []);
//echo "<h3>Get Chain ID</h3>";
//var_dump($chainId);
//
//// GET ESTIMATED GAS
//$estimateGas = $infura->call("eth_estimateGas", [["to"=>"0x0a488441E112DEC294b8458d6b92Ebd55547631D"]]);
//echo "<h3>Get Estimated Gas</h3>";
//var_dump($eth->wei()->fromWei(hexdec($estimateGas)));
//
//// GET GAS PRICE
//$gasPrice = $infura->call("eth_gasPrice", []);
//echo "<h3>Get Gas Price</h3>";
//var_dump($eth->wei()->fromWei(hexdec($gasPrice)));
//// GET Block By Hash
//$blockByHash = $infura->call("eth_getBlockByHash", ["0xdf8b805bce6f679dba03857c38f83bc69100a5ebd09c01fdc60c8d23cd38c6ff", false]);
//echo "<h3>Get Block By Hash</h3>";
//var_dump($blockByHash);
//// GET Block By Height
//$blockByHeight = $infura->call("eth_getBlockByNumber", ["0x".dechex(8952199), false]);
//echo "<h3>Get Block By Height</h3>";
//var_dump($blockByHeight);
//// GET Block Transaction Count By Hash
//$blockTransactionCountByHash = $infura->call("eth_getBlockTransactionCountByHash", ["0xdf8b805bce6f679dba03857c38f83bc69100a5ebd09c01fdc60c8d23cd38c6ff"]);
//echo "<h3>Get Block Transaction Count By Hash</h3>";
//var_dump(hexdec($blockTransactionCountByHash));
//// GET Block Transaction Count By Height
//$blockTransactionCountByHeight = $infura->call("eth_getBlockTransactionCountByNumber", ["latest"]);
//echo "<h3>Get Block Transaction Count By Height</h3>";
//var_dump(hexdec($blockTransactionCountByHeight));
//// GET Code of Smart Contract
//$getSmartContractCode = $infura->call("eth_getCode", ["0x4A303F8D845C898Cdc1fCbEE5CaD55c78e414c8A", "latest"]);
//echo "<h3>GET Code of Smart Contract</h3>";
//var_dump($getSmartContractCode);
//// GET ETH WORK
//$ethWork = $infura->call("eth_mining", []);
//echo "<h3>Get Eth Work</h3>";
//var_dump($ethWork);
//
//// GET ETH Hash Rate
//$ethHash = $infura->call("eth_hashrate", []);
//echo "<h3>Get Eth Hash Rate</h3>";
//var_dump($ethHash);
//
//// GET ETH Mining
//$ethMining = $infura->call("eth_mining", []);
//echo "<h3>Get Eth Mining</h3>";
//var_dump($ethMining);
//$tx = new FurqanSiddiqui\Ethereum\Transactions\TxBuilder($eth);
//
//$acc = new \FurqanSiddiqui\Ethereum\Accounts\Account($eth, "0xe87b69ed47a0739e6823ecd432364be86f037962");
//$tx->to("0x9cf8dbdb77a83d1f07ad19751dedac11e3812b00");
//$tx->gas(new \FurqanSiddiqui\Ethereum\Math\WEIValue("0.000000003"));
//$tx->data("0");
//$tx->value(new \FurqanSiddiqui\Ethereum\Math\WEIValue("0.5"));
//$tx->nonce(123);
//------------------------------------------------------------------------------
// GET getTransactionByHash
//$getTransactionByHash = $infura->call("eth_getTransactionByHash", ["0x35b76080480737ae2d4d1f6b1f39991827403ebb7d0b2bacce68392ca8a46b7e"]);
//echo "<h3>getTransactionByHash</h3>";
//var_dump($getTransactionByHash);
// GET eth_getTransactionCount
//$eth_getTransactionCount = $infura->call("eth_getTransactionCount", ["0xbdf8e27cd89b1bfa499cabdb956cb957cafe95cb", "latest"]);
//echo "<h3>getTransactionCount</h3>";
//var_dump(hexdec($eth_getTransactionCount));
// GET getTransactionReceipt
//$eth_getTransactionReceipt = $infura->call("eth_getTransactionReceipt", ["0x35b76080480737ae2d4d1f6b1f39991827403ebb7d0b2bacce68392ca8a46b7e"]);
//echo "<h3>getTransactionReceipt</h3>";
//var_dump($eth_getTransactionReceipt);
// GET eth_getUncleByBlockHashAndIndex
//$eth_getUncleByBlockHashAndIndex = $infura->call("eth_getUncleByBlockHashAndIndex", ["0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35", "0x0"]);
//echo "<h3>getUncleByBlockHashAndIndex</h3>";
//var_dump($eth_getUncleByBlockHashAndIndex);
// GET eth_getUncleByBlockNumberAndIndex
/*BLOCK PARAMETER [required] - an integer block number, or the string "latest", "earliest" or "pending", see the default block parameter
UNCLE INDEX POSITION [required] - a hex of the integer indicating the uncle's index position.*/
//$eth_getUncleByBlockNumberAndIndex = $infura->call("eth_getUncleByBlockNumberAndIndex", ["0x".dechex(8957238), "0x0"]);
//echo "<h3>getUncleByBlockNumberAndIndex</h3>";
//var_dump($eth_getUncleByBlockNumberAndIndex);
// GET getUncleCountByBlockHash
// BLOCK HASH [required] - a string representing the hash (32 bytes) of a block
$eth_getUncleCountByBlockHash = $infura->call("eth_getUncleCountByBlockHash", ["0x566a648676742e1e780a4dad3d1490d229eb32bb505485c238f8b577ff0f4426"]);
echo "<h3>getUncleCountByBlockHash</h3>";
var_dump(hexdec($eth_getUncleCountByBlockHash));
// GET getUncleCountByBlockNumber
// BLOCK PARAMETER [required] - an integer block number, or the string "latest", "earliest" or "pending", see the default block parameter
//$eth_getUncleCountByBlockNumber = $infura->call("eth_getUncleCountByBlockNumber", ["0x".dechex(8957238)]);
//echo "<h3>getUncleCountByBlockNumber</h3>";
//var_dump(hexdec($eth_getUncleCountByBlockNumber));
//------------------------------------------------------------------------------
//// GET Logs
//$getLogs = $infura->call("eth_getLogs", []);
//echo "<h3>GET Logs</h3>";
//var_dump($getLogs);
//// GET Storage at
//$getStorageAt = $infura->call("eth_getStorageAt", []);
//echo "<h3>GET Storage at</h3>";
//var_dump($getStorageAt);
//// GET Transaction By Block Hash and Index
//$getTransactionByBlockHashAndIndex = $infura->call("eth_getTransactionByBlockHashAndIndex", ["0x7bc717e6fe08218cd23a4047e1231c29017f29483681f0266f6dba1a6f6e3be0", "0x0"]);
//echo "<h3>GET Transaction By Block Hash and Index</h3>";
//var_dump($getTransactionByBlockHashAndIndex);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment