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
Requires
- php: >=7.4
- guzzlehttp/guzzle: ^7.4.3
- kornrunner/ethereum-offline-raw-tx: ^0.4.0
- kornrunner/keccak: ^1.0
- krowinski/bcmath-extended: ^6.0.1
- simplito/elliptic-php: ^1.0.9
- sop/crypto-encoding: ^0.2.0
- sop/crypto-types: ^0.2.1
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(); }