PHP code example of fengxin2017 / eth

1. Go to this page and download the library: Download fengxin2017/eth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fengxin2017 / eth example snippets


// transfer ETH only support geth rpcclient.

use FurqanSiddiqui\Ethereum\Accounts\Account;
use Fengxin2017\ETH\Coin\ETH;

ETH::getInstance()->from(Account|ETHADDRESS)
        ->to(Account|ETHADDRESS)
        ->amount('0x9184e72a') // hex
        ->password('xxxx')
        ->send();

ETH::getInstance()->from(Account|ETHADDRESS)
        ->to(Account|ETHADDRESS)
        ->amount('100000000000') // wei
        ->password('xxxx')
        ->send();

ETH::from(Account|ETHADDRESS)
        ->to(Account|ETHADDRESS)
        ->amountForHumans(1)
        ->password('xxxx')
        ->send();

use Fengxin2017\ETH\Facades\Geth;
use Fengxin2017\ETH\Facades\Infura;

Geth::eth_getBalance(ETHADDRESS);
Geth::eth_blockNumber();

Infura::eth_getBalance(ETHADDRESS);
Infura::eth_blockNumber();

// http://cw.hubwiz.com/card/c/ethereum-json-rpc-api/1/3/17/
// http://cw.hubwiz.com/card/c/geth-rpc-api/1/4/6/
Geth::call(METHOD_NAME,ARRAYPARAMS)

//https://infura.io/docs/ethereum/json-rpc
Infura::call(METHOD_NAME,ARRAYPARAMS)

// transfer erc20token only support geth rpcclient

use FurqanSiddiqui\Ethereum\Accounts\Account;
use Fengxin2017\ETH\Facades\Erc20;
use Fengxin2017\ETH\Facades\Geth;

Usdt::name();
Usdt::totalSupply();
Usdt::balanceOf(Account|ETHADDRESS);

YFI::name();
YFI::totalSupply();

YFII::balanceOf(Account|ETHADDRESS);

$recipt = YFII::from(Account|ETHADDRESS)
    ->to(Account|ETHADDRESS)
    ->amount(amount) 
    ->password(password)
    ->send();

// Pending will return null 
$transactionInfo = Geth::call('eth_getTransactionReceipt',[$recipt]);

.....


# OR

$usdt = Erc20::token(UsdtContractAddress);
$data = $usdt->encodedTransferData($to, $amount);
$params = [
    'from' => FROMADDRESS,
    'to' => USDTCONTRACTADDRESS,
    'value' => '0x0',
    'data' => $data
];
Geth::call('personal_sendTransaction', [
     $params, PASSWORD
]);