A simple encapsulation of Web3 framework in PHP environment

Related tags

Frameworks web3.php
Overview

Web3

A simple encapsulation of Web3 framework in PHP environment.

install

composer require kgs/web3

Usage

web3

$web3 = new Web3('https://kovan.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161');
var_dump($web3->accounts());

echo $web3->gasPrice();
echo \Web3\Utils::hexToDec($web3->getBalance("0xdB7D1B76D262D31c51d740C6fb98047B8498D851"));

Wallet

getAddress(); //0xdb7d1b76d262d31c51d740c6fb98047b8498d851 $wallet = Wallet::create(); echo $wallet->getAddress(); echo $wallet->getPrivateKey(); ">
$key = "e872122c04df93040ede8996c0e738f35a0ea44e77642d97eb5c3deedbdd4201"; 
$wallet =Wallet::createByPrivate($key);
echo $wallet->getAddress();
//0xdb7d1b76d262d31c51d740c6fb98047b8498d851
$wallet = Wallet::create();
echo $wallet->getAddress();
echo $wallet->getPrivateKey();

Contract

send($wallet,'transfer',[$toAccount,\Web3\Utils::ethToWei(1)]); echo $res; //0x43b287554146748780d00af8c7d9d42c499ba03759b759f0f4244b072ec0cab2y echo $contract->decodeEvent("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"); //Transfer $res =$contract->call('balanceOf',[$toAccount]); ">
$key = "e872122c04df93040ede8996c0e738f35a0ea44e77642d97eb5c3deedbdd4201"; 
$wallet =Wallet::createByPrivate($key);
$abi = '[{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]';
$web3 = new Web3('https://kovan.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161');
$contractAddress='0x7ef08Db1E4121b71177B828d5b5ff7a1BCB8305D';
$contract = Contract::at($web3,$abi,$contractAddress);
$toAccount = "0x6aba7cd6750225f9d732a256F0f334916C866264";
$res =$contract->send($wallet,'transfer',[$toAccount,\Web3\Utils::ethToWei(1)]);
echo $res;
//0x43b287554146748780d00af8c7d9d42c499ba03759b759f0f4244b072ec0cab2y
echo  $contract->decodeEvent("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef");
//Transfer

$res =$contract->call('balanceOf',[$toAccount]);

DONATE

 eth/dai: 0x6aba7cd6750225f9d732a256F0f334916C866264
You might also like...
Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.

Slim Framework Slim is a PHP micro-framework that helps you quickly write simple yet powerful web applications and APIs. Installation It's recommended

A simple, secure, and scalable PHP application framework

Opulence Introduction Opulence is a PHP web application framework that simplifies the difficult parts of creating and maintaining a secure, scalable w

Leaf is a PHP framework that helps you create clean, simple but powerful web apps and APIs quickly and easily.
Leaf is a PHP framework that helps you create clean, simple but powerful web apps and APIs quickly and easily.

Leaf is a PHP framework that helps you create clean, simple but powerful web apps and APIs quickly and easily. Leaf introduces a cleaner and much simpler structure to the PHP language while maintaining it's flexibility. With a simple structure and a shallow learning curve, it's an excellent way to rapidly build powerful and high performant web apps and APIs.

Woski is a fast and simple lightweight PHP Framework for building applications in the realm of the web.
Woski is a fast and simple lightweight PHP Framework for building applications in the realm of the web.

Woski is a simple fast PHP framework for the Realm The Project Installation Clone the repository $ composer create-project clintonnzedimma/woski myApp

The Hive is a simple php mvc framework
The Hive is a simple php mvc framework

Hive framework The Hive is a simple php mvc framework . Information Features : -MVC design -PDO connection -OOP system -Twig template -Very Fast, simp

Simple, fast and secure PHP Framework with easy integration.

simple-php-framework Simple, fast and secure PHP Framework with easy integration.

StaticPHP - Simple, modular php framework

StaticPHP Simple, modular php framework. Requirements PHP 8.1+ Twig 3.0+ Installation There are two ways to start using StaticPHP framework: Docker -

A simple PHP MVC framework without extra files and codes that you don't need

Welcome to (SPM) Simple PHP MVC, just what you need! This is a simple PHP MVC framework without extra files and codes that you don't need.

A simple and light-weight PHP framework
A simple and light-weight PHP framework

A simple and light-weight PHP framework

Comments
  • Fatal error: Uncaught Exception: insufficient funds for gas * price + value

    Fatal error: Uncaught Exception: insufficient funds for gas * price + value

    请问大神,我把$chainId 改成97后报这个错误是什么原因呢?钱包里的手续费和token余额都够的。 Fatal error: Uncaught Exception: insufficient funds for gas * price + value [Method] eth_sendRawTransaction in /www/wwwroot/hd.laozhao.pro/vendor/kgs/web3/src/Web3.php:785 Stack trace: #0 /www/wwwroot/hd.laozhao.pro/vendor/kgs/web3/src/Web3.php(320): Web3\Web3->request('eth_sendRawTran...', Array) #1 /www/wwwroot/hd.laozhao.pro/vendor/kgs/web3/src/Contract.php(127): Web3\Web3->sendRawTransaction('0xf8aa53850430e...') #2 /www/wwwroot/hd.laozhao.pro/test.php(15): Web3\Contract->send(Object(Web3\Wallet), 'transfer', Array) #3 {main} thrown in /www/wwwroot/hd.laozhao.pro/vendor/kgs/web3/src/Web3.php on line 785

    opened by brianchaocodes 0
Owner
于凯歌
于凯歌
I made my own simple php framework inspired from laravel framework.

Simple MVC About Since 2019, I started learning the php programming language and have worked on many projects using the php framework. Laravel is one

null 14 Aug 14, 2022
I made my own simple php framework inspired from laravel framework.

Simple MVC About Since 2019, I started learning the php programming language and have worked on many projects using the php framework. Laravel is one

Rizky Alamsyah 14 Aug 14, 2022
Framework X is a simple and fast micro framework based on PHP

Framework X is a simple and fast micro framework based on PHP. I've created a simple CRUD application to understand how it works. I used twig and I created a custom middleware to handle PUT, DELETE methods.

Mahmut Bayri 6 Oct 14, 2022
Sunhill Framework is a simple, fast, and powerful PHP App Development Framework

Sunhill Framework is a simple, fast, and powerful PHP App Development Framework that enables you to develop more modern applications by using MVC (Model - View - Controller) pattern.

Mehmet Selcuk Batal 3 Dec 29, 2022
Simple PHP framework that helps you quickly understand and write simple APIs.

Lightweight-PHP-Framework-For-APIs. Simple PHP framework that helps you quickly understand and write simple APIs. Installation Use the package manager

Youssef Hajjari 24 Jul 22, 2022
Simple PHP framework that helps you quickly understand and write simple APIs.

Lightweight PHP Framework For Web and APIs PHP framework that helps you write quickly simple but powerful web apps and APIs Installation Use the packa

Youssef Hajjari 24 Jul 22, 2022
Framework X – the simple and fast micro framework for building reactive web applications that run anywhere.

Framework X Framework X – the simple and fast micro framework for building reactive web applications that run anywhere. Quickstart Documentation Tests

Christian Lück 620 Jan 7, 2023
FuelPHP v1.x is a simple, flexible, community driven PHP 5.3+ framework, based on the best ideas of other frameworks, with a fresh start! FuelPHP is fully PHP 7 compatible.

FuelPHP Version: 1.8.2 Website Release Documentation Release API browser Development branch Documentation Development branch API browser Support Forum

Fuel 1.5k Dec 28, 2022
PHPR or PHP Array Framework is a framework highly dependent to an array structure.

this is new repository for php-framework Introduction PHPR or PHP Array Framework is a framework highly dependent to an array structure. PHPR Framewor

Agung Zon Blade 2 Feb 12, 2022
Spiral Framework is a High-Performance PHP/Go Full-Stack framework and group of over sixty PSR-compatible components

Spiral HTTP Application Skeleton Spiral Framework is a High-Performance PHP/Go Full-Stack framework and group of over sixty PSR-compatible components.

Spiral Scout 152 Dec 18, 2022