定制 sinyakinilya/ethereum-geth-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sinyakinilya/ethereum-geth-client

Composer 安装命令:

composer require sinyakinilya/ethereum-geth-client

包简介

README 文档

README

Client use guzzlehttp/guzzle;

All method json-rpc-methods

Example:

include_once 'vendor/autoload.php';

use SinyakinIlya\Ethereum\Client;
use SinyakinIlya\Ethereum\Helper\Hash;

$walletAccount = '0x...';

//geth must be run with params: geth --rpc --rpcaddr 0.0.0.0 --rpcapi admin,miner,shh,txpool,personal,eth,net,web3
$ip = '..ip..';
$port = 8545;

 
$client = new Client($ip, $port);

$lastBlock = $client->callMethod('eth_blockNumber');
$currentBockNumber = Hash::hexToNumber($lastBlock);
$toTransactions = $fromTransactions = [];

do {
    $block = $client->callMethod('eth_getBlockByNumber', [Hash::toHex($currentBockNumber), true]);
    if (!is_array($block)) {
        break;
    }
    foreach ($block['transactions'] as $transaction) {
        if ($transaction['from'] == $walletAccount) {
            $fromTransactions[$transaction['to']][] = $transaction;
        } elseif ($transaction['to'] == $walletAccount) {
            $toTransactions[$transaction['from']][] = $transaction;
        }
    }
    echo 'Process block: ', $currentBockNumber--, PHP_EOL;
} while ($currentBockNumber >= 4000000);

file_put_contents('tr.json', json_encode(['f' => $fromTransactions, 't' => $toTransactions]));

Example: send transaction with calling smart-contract function

include_once 'vendor/autoload.php';

use SinyakinIlya\Ethereum\Client;
use SinyakinIlya\Ethereum\Helper\Hash;
use SinyakinIlya\Ethereum\Helper\SmartContract;

$ip           = '0.0.0.0';             // geth address 
$addressSC    = '0x0c328e06....';
$ownerAddress = '0x978bEE7F....';
$ABI          = 'sc-abi.json';         // file with ABI for smart-contract

$senderAddress = '0x5237BC08b2FE....';
$senderPassPhrase = '..passphrase..';

$client = new Client($ip);
$sc     = new SmartContract($client);
$sc->setAddress($addressSC);
$sc->setContractInterface(file_get_contents($ABI));


function sendTransferFrom($from, $txData, $passphrase)
{
    global $sc, $client;
    $functionSignature = 'transferFrom(address,address,uint256)';     //this is string you get from $sc->getFunctions();
    $inputData = $sc->createSandRawData($functionSignature, $txData);
    $params = new stdClass;
    $params->from = $from;
    $params->to = $sc->getAddress();
    $params->gas = Hash::toHex(1000000);
    $params->gasPrice = $client->callMethod('eth_gasPrice');
    $params->value = Hash::toHex(0);
    $params->data = $inputData[$functionSignature];

    return $client->callMethod('personal_sendTransaction', [$params, $passphrase]);
}

$data = [
    $ownerAddress,   // from address
    $senderAddress,  // to adderss
    12345            // amount tokens
];

$txHash = sendTransferFrom($senderAddress, $data, $senderPassPhrase);
echo $txHash, PHP_EOL;

Help and docs

Installing

The recommended way to install Client is through Composer.

# Install Composer
curl -sS https://getcomposer.org/installer | php

Next, run the Composer command to install the latest stable version:

php composer.phar require sinyakinilya/ethereum-geth-client

After installing, you need to require Composer's autoloader:

require 'vendor/autoload.php';

sinyakinilya/ethereum-geth-client 适用场景与选型建议

sinyakinilya/ethereum-geth-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 176 次下载、GitHub Stars 达 6, 最近一次更新时间为 2017 年 08 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 sinyakinilya/ethereum-geth-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sinyakinilya/ethereum-geth-client 我们能提供哪些服务?
定制开发 / 二次开发

基于 sinyakinilya/ethereum-geth-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 176
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-03