kompendium-llc / factom-php-client
访问Factom区块链的客户端库
1.0.0
2020-01-22 12:43 UTC
Requires
- php: >=7.0.0
- vaderangry/php-json-rpc: dev-master
This package is auto-updated.
Last update: 2024-09-22 23:04:33 UTC
README
Factom协议的JSON-RPC Php客户端。每个响应都有一个独特的类型,这些类型自动从JSON响应中转换而来,非常适合在业务逻辑中使用。所有响应都在响应目录中提供,并附带方便的转换器。
安装
Composer:
composer require kompendium-llc/factom-php-client
Git:
git clone https://github.com/kompendium-llc/factom-php-client.git
配置
You can change default node url or ports
Add this lines after this -
require_once __DIR__ . '/../vendor/autoload.php';
// Set Custom host of node
define('walletHost', 'https://dev.factomd.net/v2');
define('host', 'https://dev.factomd.net/v2');
define('debugHost', 'https://:8088/debug');
使用
require_once __DIR__ . '/../vendor/autoload.php';; require_once __DIR__.'/../vendor/kompendium/factom-api-php/config.php'; use Factom\Api\Blocks;
检索余额
use Factom\Api\Factoid; result = Factoid::factoidBalance("EC2dTBH2Nc9t9Y7RFD3FYMN5ottoPeHdk6xqUWEc6eHVoBPj6CmH"); print_r(result);
读取条目数据
# factomd -> entry api use Factom\Api\Entry; result = Entry::entry("61b3d3175f211f3b23b455bb8710fdbcf545cb40da397d9e20b26eca31c389a6"); print_r(result);
写入条目
注意:确保条目字段中的数据是十六进制编码的。这包括内容部分。
use Factom\Api\Entry; $composeEntry = Entry::composeEntry("48e0c94d00bf14d89ab10044075a370e1f55bcb28b2ff16206d865e192827645","EC2DKSYyRcNWf7RS963VFYgMExo1824HVeCfQ9PGPmNzwrcmgm2r"); print_r($composeEntry); use Factom\Api\Commits; $commitEntry = Commits::commitEntry("00015507C1024BF5C956749FC3EBA4ACC60FD485FB100E601070A44FCCE54FF358D60669854734013B6A27BCCEB6A42D62A3A8D02A6F0D73653215771DE243A63AC048A18B59DA29F4CBD953E6EBE684D693FDCA270CE231783E8ECC62D630F983CD59E559C6253F84D1F54C8E8D8665D493F7B4A4C1864751E3CDEC885A64C2144E0938BF648A00"); print_r($commitEntry); use Factom\Api\Entry; $revealEntry = Entry::revealEntry("007E18CCC911F057FB111C7570778F6FDC51E189F35A6E6DA683EC2A264443531F000E0005746573745A0005746573745A48656C6C6F20466163746F6D21"); print_r($revealEntry);
区块高度和当前分钟
# factomd -> Get Height use Factom\Api\FactomWalletd; $getheight = FactomWalletd::getHeight(); print_r($getheight); # factomd -> current minute use Factom\Api\Minute; $currentMinute = Minute::currentMinute(); print_r($currentMinute);
发送交易
# send transaction use Factom\Api\Transaction; $data = [ "txname" => "test1234", "inputAddress" => "FA2jK2HcLnRdS94dEcU27rF3meoJfpUcZPSinpb7AwQvPRY6RL1Q", "inputAmount" => 1000012000, "outputAddress" => "FA2yeHMMJR6rpjRYGe3Q4ogThHUmByk3WLhTjQDvPrxDoTYF8BbC", "outputAmount" => 1000000000 ]; $transaction = Transaction::sendTransaction($data); print_r($transaction);
测试
$ php tests/blocks.php $ php tests/chains.php $ php tests/commits.php $ php tests/debug.php $ php tests/entry.php $ php tests/factoid.php $ php tests/factomaddress.php $ php tests/factomd.php $ php tests/factomwalletd.php $ php tests/minute.php $ php tests/pending.php $ php tests/security.php $ php tests/transaction.php
此外,测试由Travis CI执行,配置指向Factom的Open Node(https://factomd.net)。
示例
在示例文件夹中找到
支持
有关Factom协议或库使用的额外支持,可以在discord找到。
开发
要为factom-php-client
库做出贡献,请克隆存储库,创建一个功能分支,然后提交一个PR以供审查。
学习
贡献
该库由Kompendium,LLC与Kelecorix,Inc和Sergey Bushnyak合作开发,以促进Factom社区的发展。尽管我们几个月来看到库的使用情况,但Factom社区多次决定不以预先授予或作为多次报酬的形式支持这项工作(1, 2, 3)
如果您是活跃用户或认为这很有用,我们强烈鼓励您支持我们的努力,并通过向以下加密货币地址之一捐赠一小笔资金来确保长期维护:
BTC: 39oVXpsgsyW8ZgzsnX3sV7HLdtXWfT96qN
ETH: 0x9cDBA6bb44772259B3A3fb89cf233A147a720f34
FCT: FA38cwer93mmPw1HxjScLmK1yF9iJTu5P87T2vdkbuLovm2YXyss