Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gri3li/php-ethereum-smart-contract
PHP wrapper for interacting with Ethereum smart contracts
https://github.com/gri3li/php-ethereum-smart-contract
ethereum solidity
Last synced: 11 days ago
JSON representation
PHP wrapper for interacting with Ethereum smart contracts
- Host: GitHub
- URL: https://github.com/gri3li/php-ethereum-smart-contract
- Owner: gri3li
- License: mit
- Created: 2019-03-18T04:40:49.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-30T18:09:08.000Z (almost 5 years ago)
- Last Synced: 2024-05-18T05:02:43.091Z (6 months ago)
- Topics: ethereum, solidity
- Language: PHP
- Homepage:
- Size: 4.88 KB
- Stars: 10
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Ethereum Smart Contract
===Ethereum Smart Contract Wrapper
Install
------------
```
composer require gri3li/ethereum-smart-contract
```Usage
-----Create contract instance:
```php
use gri3li\EthereumSmartContract;$instance = EthereumSmartContract::createByHost(
'http://localhost:8545',
'1', // mainnet
'0xB8c77482e45F1F44dE1745F52C74426C631bDD52', // contract address
file_get_contents('path_to_contract_abi_file.json') // abi string
);
```Reading, for example, erc20 token get balance:
```php
$response = $instance->read('balanceOf', ['0x227390eeba512120c16C239B6556C0992022E961']);
var_dump($response);/* array(1) {
'balance' =>
class phpseclib\Math\BigInteger#47 (2) {
public $value =>
string(24) "0x01c3ca8bcdc38115a80020"
public $engine =>
string(3) "gmp"
}
} *//** @var \BI\BigInteger $balance */
$balance = $response['balance'];
var_dump($balance->toString());```
Writing, for example, erc20 token send transfer:
```php
$fromPrivateKey = '4ffe6b52e5f649794dd4f75ed91276ad0dd417ec24cd24ba22802ea50e9d34fd';
$toAddress = '0x227390eeba512120c16C239B6556C0992022E962';
$amount = '1000000000000000000';
$gasLimit = '800000';
$gasPrice = '12000000000';
$txHash = $instance->write('transfer', [$toAddress, $amount], $fromPrivateKey, $gasPrice, $gasLimit);
```