amendozadev/eth_rpc

Create Ethereum wallet and/or connect to JSON-RPC Endpoint from Ethereum or compatibles like BSC

v1.0.0 2022-05-27 01:14 UTC

This package is auto-updated.

Last update: 2024-03-27 16:53:43 UTC


README

Create Ethereum wallet and/or connect to JSON-RPC Endpoint from Ethereum or compatibles like BSC

This library requires the bcmath PHP extension.

Installation:

composer require amendozadev/eth_rpc

Usage:

$wallet = new \aMendoza\Eth_rpc\Wallet();

//Create new wallet
$account = $wallet->createWallet(); //['address' => '0xf1b4d0755ef13025c8b1b398237652b7c3ea8dc0', 'private_key' => '81011e578366208ab232d726cb910d1dffd132c84659cede2bfc6b5d0404d234'] 
		
//Connect to RPC URL (URL : Chain ID)
$wallet->rpc_url('https://ropsten.infura.io/v3/', 3);

// get gas price in wei
$wei = $wallet->gasPrice();
echo $wei; // "5000000000"

// convert to eth:
$eth = $wallet->wei2eth($wei);
echo $eth; // "0.000000005000000000"

// block number
$block = $wallet->blockNumber();
echo $block; //18143442

// account balance
$balance = $wallet->getBalance($account['address']);

//Send Transaction
try {
    $to = '0xa48e2ff1e6e4ef5952c64dc505d6983a92d320f7';
    $nonce = 0;
    $gasPrice = 10;
    $gasLimit = 21000;
	$raw = $wallet->createTransaction($account['address'], $to, '0.0002', $account['private_key'], $nonce, $gasPrice, $gasLimit);
	echo $wallet->sendTransaction($raw); //0xa91377938abd362e2486398d467a6c7c96b1100424ef1d20318e82bffbd8f0e8
}catch (Exception $exception){
	echo $exception->getMessage();
}

Crypto

Ethereum 0x05836377EB43a0Fe0d88C0D75E101396eAbbb8fb

Binance 0x9C2E46Ca7FA1F483C7CE40a415801351a73FEd90