Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Feb 9, 2023. It is now read-only.
/web3Public archive

⚡️ Web3 PHP is a supercharged PHP API client that allows you to interact with a generic Ethereum RPC.

License

NotificationsYou must be signed in to change notification settings

web3-php/web3

Repository files navigation

Web3 PHP

GitHub Workflow Status (master)Total DownloadsLatest VersionLicense


Web3 PHP is a supercharged PHP API client that allows you to interact with a generic Ethereum RPC.

This project is a work-in-progress. Code and documentation are currently under development and are subject to change.

Get Started

RequiresPHP 8.0+

First, install Web3 via theComposer package manager:

composer require web3-php/web3 dev-master

Then, interact with a local (web3-php/cli) or remote ethereum node:

useWeb3\Web3;$web3 =newWeb3('http://127.0.0.1:8545');$accounts =$web3->eth()->accounts();// ['0x54a3259f4f693e4c1e9daa54eb116a0701edc403', ...]

Usage

Web3 Namespace

clientVersion

TheclientVersion method returns the version of the current client.

$web3->clientVersion();// TestRPC v2.13.2

sha3

Thesha3 method hashes data using the Keccak-256 algorithm.

$web3->sha3('string');// 0x348ab0847d053bb0150c1eb3470a71071d2967e20cf131b59dea3df9bf8f753e

Eth Namespace

accounts

Theaccounts method returns a list of addresses owned by this client.

$web3->eth()->accounts();// ['0x54a3259f4f693e4c1e9daa54eb116a0701edc403', ...]

chainId

ThechainId method returns the current chain id.

$web3->eth()->chainId();// 1

gasPrice

ThegasPrice method returns the current price of gas in wei.

$web3->eth()->gasPrice()->toEth();// 0.00000002

getBalance

ThegetBalance method returns the balance of an address in wei.

$web3->eth()->getBalance('0x54a3259f4f693e4c1e9daa54eb116a0701edc403')->toEth();// 100

getBlockTransactionCountByHash

ThegetBlockTransactionCountByHash method returns the number of transactions in a block by its hash.

$web3->eth()->getBlockTransactionCountByHash('0xd2a91777651a08b92d1d9fc701982c79da2249532cfe41a773a340978f96b5d1');// 266

getTransactionByHash

ThegetTransactionByHash method returns information about a transaction by its hash.

$web3->eth()->getTransactionByHash('0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b');

getTransactionReceipt

ThegetTransactionReceipt method returns the receipt for a transaction by its hash.

$web3->eth()->getTransactionReceipt('0xbb3a336e3f823ec18197f1e13ee875700f08f03e2cab75f0d0b118dabb44cba0');

getUncleCountByBlockHash

ThegetUncleCountByBlockHash method returns the number of uncles in a block by its hash.

$web3->eth()->getUncleCountByBlockHash('0xd2a91777651a08b92d1d9fc701982c79da2249532cfe41a773a340978f96b5d1');// 266

hashrate

Thehashrate() method returns the number of hashes-per-second this node is mining at.

$web3->eth()->hashrate();// '65'

isMining

TheisMining() method determines if the client is mining new blocks.

$web3->eth()->isMining();// true

blockNumber

TheblockNumber() method returns the number (quantity) of the most recent block seen by this client.

$web3->eth()->blockNumber();// '3220'

coinbase

Thecoinbase() method returns the Coinbase address of the client.

$web3->eth()->coinbase();// '0xc014ba5ec014ba5ec014ba5ec014ba5ec014ba5e'

sendTransaction

ThesendTransaction method creates, signs, and sends a new transaction to the network.

useWeb3\ValueObjects\{Transaction,Wei};$from ='0xc9257b94da7f8eb07537db73a4ad0603cd83aba4';$to ='0x108d1089e4a737c0be63527a6e464564be948b03';$value = Wei::fromEth('1');$transaction = Transaction::between($from,$to)->withValue($value);$web3->eth()->sendTransaction($transaction);// '0xa124a7de5177cf5cedd3c44e91d115d0011f915905fa36fb7c000a491fa536ee'

submitWork

ThesubmitWork() method submits a proof-of-work solution, and returns a boolean based on the result.

$web3->eth()->submitWork($nonce,$proofOfWorkHash,$mixDigest);// true

Net Namespace

listening

Thelistening method determines if this client is listening for new network connections.

$web3->net()->listening();// true

peerCount

ThepeerCount method returns the number of peers currently connected to this client.

$web3->net()->peerCount();// 230

version

Theversion method returns the chain ID associated with the current network.

$web3->net()->version();// 1637712995212

Web3 PHP is an open-sourced software licensed under theMIT license.

About

⚡️ Web3 PHP is a supercharged PHP API client that allows you to interact with a generic Ethereum RPC.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

  •  

Contributors6

Languages


[8]ページ先頭

©2009-2025 Movatter.jp