All Projects → myxtype → eos-client

myxtype / eos-client

Licence: other
PHP library of simple and extensible to use eos rpc and offline signature.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to eos-client

ethereum-client
ethereum rpc client
Stars: ✭ 34 (-20.93%)
Mutual labels:  offline, rpc
eosdart ecc
Elliptic curve cryptography functions in Dart. Private Key, Public Key, Signature, AES, Encryption, Decryption
Stars: ✭ 25 (-41.86%)
Mutual labels:  signature, eos
Plotly Offline Python
This repository provide tutorials regarding using Plotly offline package in python.
Stars: ✭ 61 (+41.86%)
Mutual labels:  offline
dolphin
Automated code tool for Golang
Stars: ✭ 27 (-37.21%)
Mutual labels:  rpc
wordpress
Free PWA & SPA for Wordpress & Woocommerce
Stars: ✭ 103 (+139.53%)
Mutual labels:  offline
moleculer-go
moleculer go implementation
Stars: ✭ 17 (-60.47%)
Mutual labels:  rpc
signatory
Differentiable computations of the signature and logsignature transforms, on both CPU and GPU. (ICLR 2021)
Stars: ✭ 153 (+255.81%)
Mutual labels:  signature
Pudding
Pudding 是一款迷你级分布式服务框架
Stars: ✭ 24 (-44.19%)
Mutual labels:  rpc
spring-boot-protocol
springboot功能扩充-netty动态协议,可以支持各种网络协议的动态切换(单端口支持多个网络协议).支持mmap,sendfile零拷贝,http请求批量聚合
Stars: ✭ 68 (+58.14%)
Mutual labels:  rpc
aws-appsync-refarch-offline
AWS AppSync offline reference architecture powered by the Amplify DataStore
Stars: ✭ 47 (+9.3%)
Mutual labels:  offline
bloomfilter
Bloomfilter written in Golang, includes rotation and RPC
Stars: ✭ 61 (+41.86%)
Mutual labels:  rpc
gostcoin
GOST R 34.11-2012 algo, GOST R 34.10-2012 signature
Stars: ✭ 31 (-27.91%)
Mutual labels:  signature
Python-notes
Python related technologies used in work: crawler, data analysis, timing tasks, RPC, page parsing, decorator, built-in functions, Python objects, multi-threading, multi-process, asynchronous, redis, mongodb, mysql, openstack, etc.
Stars: ✭ 104 (+141.86%)
Mutual labels:  rpc
lightning-rpc-explorer
Simple, self-hosted lightning network explorer.
Stars: ✭ 45 (+4.65%)
Mutual labels:  rpc
polix
🚀 Node.js Web Framework
Stars: ✭ 32 (-25.58%)
Mutual labels:  rpc
electron-ipc-bus
An IPC bus for Electron.
Stars: ✭ 23 (-46.51%)
Mutual labels:  rpc
simple-rpc-plus
使用netty和zookeeper技术实现的远程调用框架
Stars: ✭ 16 (-62.79%)
Mutual labels:  rpc
seeds light wallet
www.joinseeds.earth/
Stars: ✭ 30 (-30.23%)
Mutual labels:  eos
qml-oled-renderer
Renders QML applications to an SSD1309 OLED screen
Stars: ✭ 21 (-51.16%)
Mutual labels:  offline
tidalRPC
Discord Rich Presence for Tidal
Stars: ✭ 15 (-65.12%)
Mutual labels:  rpc

eos-client

eos client offline signature for PHP

针对PHP的EOS RPC客户端,另外提供EOS-ECC方法和离线交易。

Install

composer.json

{
    "require": {
        "myxtype/eos-client": "dev-master"
    }
}

然后composer update即可。

或者直接 composer require myxtype/eos-client:dev-master

Initialization

use xtype\Eos\Client as EosClient;

$client = new EosClient('http://api-kylin.eosasia.one');

GuzzleHttp Options.

$client = new EosClient([
    'base_uri' => 'http://api-kylin.eosasia.one',
    'timeout' => 20,
]);

RPC

You can visit https://developers.eos.io/eosio-nodeos/v1.4.0/reference View all RPC Method.

  • set version(设置版本)
// set version
$client->version(1);
// or
$client->version(1)->chain();
// or
$client->version('v1')->chain();
  • chain
$chain = $client->chain();
// You can do this
// will visit http://api-kylin.eosasia.one/v1/chain/get_info
var_dump($chain->getInfo());
// or
var_dump($chain->get_info());
// or
var_dump($client->chain()->get_info()->chain_id);
// string(64) "5fff1dae8dc8e2fc4d5b23b2c7665c97f9e9d8edf2b6485a86ba311c25639191"

// get_block
var_dump($chain->getBlock(['block_num_or_id' => 5]));
  • history
$history = $client->history();
var_dump($history->getTransaction([
    'id' => '5fff1dae8dc8e2fc4d5b23b2c7665c97f9e9d8edf2b6485a86ba311c25639191'
]));
  • net
$net = $client->net();
var_dump($net->status());
  • producer
$producer = $client->producer();
  • wallet
$wallet = $client->wallet();
// Signature transaction if you have opened your wallet RPC
$wallet->sign_transaction([
    'txn' => '',
    'keys' => '',
    'id' => '',
]);
  • Error(错误信息)

在使用RPC过程中,你可能需要获取错误信息

try {
    // get_block
    var_dump($client->chain()->getBlock(['id' => 5]));
} catch(\Exception $e) {
    var_dump($client->getError());
}

如果有错误信息,将返回一个类似下面的对象。

object(stdClass)#21 (3) {
  ["code"]=>
  int(500)
  ["message"]=>
  string(22) "Internal Service Error"
  ["error"]=>
  object(stdClass)#35 (4) {
    ["code"]=>
    int(3010008)
    ["name"]=>
    string(23) "block_id_type_exception"
    ["what"]=>
    string(16) "Invalid block ID"
    ["details"]=>
    array(1) {
      [0]=>
      object(stdClass)#18 (4) {
        ["message"]=>
        string(78) "Invalid Block number or ID, must be greater than 0 and less than 64 characters"
        ["file"]=>
        string(16) "chain_plugin.cpp"
        ["line_number"]=>
        int(1396)
        ["method"]=>
        string(9) "get_block"
      }
    }
  }
}
  • notice(说明)

Interface parameters need to be filled in according to the official EOS document. These methods are not fixed. If EOS officially updates the interface, you can modify it directly according to the above, without updating the code of EosClient.

接口参数需要按照EOS官方文档来填写。这些方法都不是固定的,如果EOS官方更新了接口,你直接按照上面修改就行,不必更新EosClient的代码。

ECC

https://github.com/EOSIO/eosjs-ecc

  • privateToPublic
use xtype\Eos\Ecc;

$privateWif = '5**********';
$public = Ecc::privateToPublic($privateWif);
var_dump($public);
// EOS7nCpUfHCPqAhu2qkTXSPQYmFLAt58gsmdFRtGCD2CNYcnWdRd3
  • randomKey
use xtype\Eos\Ecc;

// 随机生成私钥
$randomKey = Ecc::randomKey();
var_dump($randomKey);
// 5KBRW5yz1syzQcJCFUmnDeoxBX6JoZ3UpwQk5r6uKKFfGajM8SA
  • seedPrivate
use xtype\Eos\Ecc;

$privateWif = Ecc::seedPrivate('secret');
var_dump($privateWif);
// 5J9YKiVU3AWNkCa2zfQpj1f2NAeMQhLsYU51N8NM28J1bMnmrEQ
  • isValidPublic
  • isValidPrivate
  • sign
  • signHash

Offline transaction

Offline Signature and Transaction

  • Send EOS or other(发送代币)
use xtype\Eos\Client;

$client = new Client('http://api-kylin.eosasia.one');
// set your private key
// 在这里设置你的私钥
$client->addPrivateKeys([
    '5JC6gzzaKU4L6dP7AkmRPXJMcYqJxJ8iNB9tNwd2g4VbpRf5CPC'
]);

$tx = $client->transaction([
    'actions' => [
        [
            'account' => 'eosio.token',
            'name' => 'transfer',
            'authorization' => [[
                'actor' => 'xtypextypext',
                'permission' => 'active',
            ]],
            'data' => [
                'from' => 'xtypextypext',
                'to' => 'mysuperpower',
                'quantity' => '0.1000 EOS',
                'memo' => '',
            ],
        ]
    ]
]);
echo "Transaction ID: {$tx->transaction_id}";
// Transaction ID: 15ece6b6f0028e36919f9f208b47ae24233e5ae67a8f15319ad317d3e8be1a2a
  • Buy Ram(购买内存)
// 你甚至可以使用PHP链式调用对象方方法
$tx = $client->addPrivateKeys(['5JC6gzzaKU4L6dP7AkmRPXJMcYqJxJ8iNB9tNwd2g4VbpRf5CPC'])->transaction([
    'actions' => [
        [
            'account' => 'eosio',
            'name' => 'buyram',
            'authorization' => [[
                'actor' => 'xtypextypext',
                'permission' => 'active',
            ]],
            'data' => [
                'payer' => 'xtypextypext',
                'receiver' => 'mysuperpower',
                'quant' => '0.1000 EOS',
            ],
        ]
    ]
]);
echo "Transaction ID: {$tx->transaction_id}";
// Transaction ID: 15ece6b6f0028e36919f9f208b47ae24233e5ae67a8f15319ad317d3e8be1a2a
  • delegatebw(抵押来得到CPU和NET)
$tx = $client->addPrivateKeys(['5JC6gzzaKU4L6dP7AkmRPXJMcYqJxJ8iNB9tNwd2g4VbpRf5CPC'])->transaction([
    'actions' => [
        [
            'account' => 'eosio',
            'name' => 'delegatebw',
            'authorization' => [[
                'actor' => 'xtypextypext',
                'permission' => 'active',
            ]],
            'data' => [
                'from' => 'xtypextypext',
                'receiver' => 'mysuperpower',
                'stake_net_quantity' => '0.1000 EOS',
                'stake_cpu_quantity' => '0.1000 EOS',
                'transfer' => false,
            ],
        ]
    ]
]);
echo "Transaction ID: {$tx->transaction_id}";
  • New Account (新建账户)
// 新建账号
$newAccount = 'ashnbjuihgt1';
// randomKey 随机生成KEY
$activePublicKey = Ecc::privateToPublic(Ecc::randomKey());
$ownerPublicKey = Ecc::privateToPublic(Ecc::randomKey());
var_dump($newAccount, $activePublicKey, $ownerPublicKey);

$tx = $client->addPrivateKeys(['5JC6gzzaKU4L6dP7AkmRPXJMcYqJxJ8iNB9tNwd2g4VbpRf5CPC'])->transaction([
    'actions' => [
        [
            'account' => 'eosio',
            'name' => 'newaccount',
            'authorization' => [[
                'actor' => 'xtypextypext',
                'permission' => 'active',
            ]],
            'data' => [
                'creator' => 'xtypextypext',
                // Main net key is name
                'newact' => $newAccount,
                'owner' => [
                    'threshold' => 1,
                    'keys' => [
                        ['key' => $ownerPublicKey, 'weight' => 1],
                    ],
                    'accounts' => [],
                    'waits' => [],
                ],
                'active' => [
                    'threshold' => 1,
                    'keys' => [
                        ['key' => $activePublicKey, 'weight' => 1],
                    ],
                    'accounts' => [],
                    'waits' => [],
                ],
            ],
        ],
        [
            'account' => 'eosio',
            'name' => 'buyram',
            'authorization' => [[
                'actor' => 'xtypextypext',
                'permission' => 'active',
            ]],
            'data' => [
                'payer' => 'xtypextypext',
                'receiver' => $newAccount,
                'quant' => '0.2500 EOS',
            ],
        ],
        [
            'account' => 'eosio',
            'name' => 'delegatebw',
            'authorization' => [[
                'actor' => 'xtypextypext',
                'permission' => 'active',
            ]],
            'data' => [
                'from' => 'xtypextypext',
                'receiver' => $newAccount,
                'stake_net_quantity' => '0.3000 EOS',
                'stake_cpu_quantity' => '0.2000 EOS',
                'transfer' => false,
            ],
        ]
    ]
]);
echo "Transaction ID: {$tx->transaction_id}";
// string(12) "ashnbjuihgt1"
// string(53) "EOS4uioRoFXsht5ExeD2v53BNWNE3MoEezMLzF6ZbxqzP1hAhmfdp"
// string(53) "EOS8f3Cc8ex7zcgHH2xWcC1QgYQQTbio5DRRoCksteoX4PEnQyA4o"
// Transaction ID: d556e1abbe108e72d3ae2d1b0e1c9e581b95fa21931dee80e77175fd14322ffb
  • Maintain(维护)

This project has been optimized and maintained. If you have a better plan, I hope you can join this project.

这个项目一直在优化和维护,如果你有更好的方案,希望你能加入这个开源项目。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].