mayvenstudios/flow-php-sdk
Composer 安装命令:
composer require mayvenstudios/flow-php-sdk
包简介
PHP SDK for the Flow blockchain
README 文档
README
⚠️ This is an alpha release; functionality may change.
This is a Laravel PHP package that allows you to interact with the Flow blockchain by using the Flow CLI.
In the future we'll make a full integration with the GRPC interface, but for now it's just a wrapper around the Flow CLI.
At the moment, the SDK includes the following features:
- Wrapper around Flow CLI for basic scripts, transactions, events and block calls.
- Communication with the Flow Access API over gRPC (coming soon)
- Transaction preparation and signing (coming soon)
- Events parsing (coming soon)
Installation
Composer
To add this SDK to your project using Composer, use the following:
composer require mayvenstudios/flow-php-sdk
Environment variables
After this, you should add the following variables in your .env file.
This example shows the default Flow CLI path for macOS if you're using Homebrew, but on a Linux server it will likely be ~/.local/bin
FLOW_PATH=/opt/homebrew/bin/
FLOW_NETWORK=testnet
Cadence folder
It's very important that you put all your flow.json config file and the contracts, scripts and transactions in a folder called cadence in the root directory of your project.
This folder will be used as the base path to run the flow command, so that it will be able to read all the necessary Flow configurations.
Config file (optional)
If you're using Laravel you can also run this command to publish the config files if you need.
php artisan vendor:publish
Install the grpc extension (optional)
This is only needed if you want to help develop the full GRPC version.
$ [sudo] pecl install grpc
Example Usage
Once you have added the package via Composer and setup the environment variables, you can use the Flow Facade in the following ways.
Please remember to import the class at the beginning of your PHP with use Flow;
All the output will be returned as PHP Object parsed from the JSON returned by the Flow CLI.
Get the latest Block
Flow::getLatestBlock();
Get the latest Block by ID
Flow::getBlock(123456);
Get Events within a range of Blocks (250 max)
Flow::event('event_name_with_address_goes_here')->minBlock(1)->maxBlock(100)->run();
Run a script
Flow::script('path_to_cadence_script_file')->run();
Execute a transaction
Flow::transaction('path_to_cadence_transaction_file')->run();
Arguments
You can easily pass arguments to the script and transactions by using the following methods
Integer (UInt64)
Flow::transaction('path_to_cadence_transaction_file')->argInt(100)->run();
Fix (UFix64)
Flow::transaction('path_to_cadence_transaction_file')->argFix(9.99)->run();
String
Flow::transaction('path_to_cadence_transaction_file')->argString('something')->run();
Address
Flow::transaction('path_to_cadence_transaction_file')->argAddress('0x711eba2a0d39d21a')->run();
Bool
Flow::transaction('path_to_cadence_transaction_file')->argBool(true)->run();
DictionaryString (Dictionary of {String:String})
Flow::transaction('path_to_cadence_transaction_file')->argDictionaryString(['key' => 'value'])->run();
Contribution
Project is in the very early phase, all contributions are welcomed.
Read the contributing guide to get started.
Dependencies
Protobuf-PHP Illuminate-Support
License
mayvenstudios/flow-php-sdk 适用场景与选型建议
mayvenstudios/flow-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 215 次下载、GitHub Stars 达 9, 最近一次更新时间为 2021 年 03 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mayvenstudios/flow-php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mayvenstudios/flow-php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 215
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2021-03-10