Coder Social home page Coder Social logo

eth_rpc's Introduction

Ethereum account and JSON-RPC client

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.