iconation/icon-sdk-php
Composer 安装命令:
composer require iconation/icon-sdk-php
包简介
SDK to communicate with the ICON blockchain
README 文档
README
ICON SDK for PHP
This is an SDK to communicate with the ICON blockchain, built for PHP.
Disclaimer: I cannot guarantee optimal performance of this software. It is provided as is and without any assurances. Use it at your own risk.
Features
Fully or partially supports all Iconservice functions, IRC-2 tokens and IISS calls.
Requirements & Installation
Make sure you're using >=php7.2. Then check if you already have or install the required php extensions:
apt install php-curl php-xml php-gmp php-bcmath
Require the package in the composer.json file in your project:
composer require iconation/icon-sdk-php --no-dev
Testing
apt install php-mbstring
composer install
composer test
Usage
Iconservice:
- icx_getLastBlock
use iconation\IconSDK\IconService\IconService; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $res = $iconservice->getLastBlock();
- icx_getBlockByHeight
use iconation\IconSDK\IconService\IconService; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $res = $iconservice->getBlockByHeight('0x3');
- icx_getBlockByHash
use iconation\IconSDK\IconService\IconService; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $res = $iconservice->getBlockByHash('0x123986e1c834632f6e65915c249d81cd01453ec915e3370d364d6df7be5e6c03');
- icx_call
use iconation\IconSDK\IconService\IconService; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $score = "cx9ab3078e72c8d9017194d17b34b1a47b661945ca"; $params = new stdClass(); $params->method = "balanceOf"; $params->params = new stdClass(); $params->params->_owner = "hx70e8eeb5d23ab18a828ec95f769db6d953e5f0fd"; $res = $iconservice->call($score, $params);
- icx_getBalance
use iconation\IconSDK\IconService\IconService; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $res = $iconservice->getBalance('hx70e8eeb5d23ab18a828ec95f769db6d953e5f0fd');
- icx_getScoreApi
use iconation\IconSDK\IconService\IconService; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $score = "cx9ab3078e72c8d9017194d17b34b1a47b661945ca"; $res = $iconservice->getBalance($score);
- icx_getTotalSupply
use iconation\IconSDK\IconService\IconService; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $res = $iconservice->getTotalSupply();
- icx_getTransactionResult
use iconation\IconSDK\IconService\IconService; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $txHash = '0xb89690b7598e07c286db87f05c1ee4cfc1cf915bf061007ac3404a42dc4979e9'; $res = $iconservice->getTransactionResult($txHash);
- icx_getTransactionByHash
use iconation\IconSDK\IconService\IconService; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $txHash = '0xb89690b7598e07c286db87f05c1ee4cfc1cf915bf061007ac3404a42dc4979e9'; $res = $iconservice->getTransactionByHash($txHash);
- ise_getStatus
use iconation\IconSDK\IconService\IconService; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $keys = ['lastBlock']; $res = $iconservice->getStatus($keys);
- icx_sendTransaction
use iconation\IconSDK\IconService\IconService; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $private_key = "3468ea815d8896ef4552f10768caf2660689b965975c3ec2c1f5fe84bc3a77a5"; //Sender's private key $from = "hx8dc6ae3d93e60a2dddf80bfc5fb1cd16a2bf6160"; $to = "hxf8689d6c4c8f333651469fdea2ac59a18f6c242d"; $value = "0x2386f26fc10000"; // = 0.01 ICX $res = $iconservice->send($from, $to, $value, $private_key);
- message
use iconation\IconSDK\IconService\IconService; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $private_key = "3468ea815d8896ef4552f10768caf2660689b965975c3ec2c1f5fe84bc3a77a5"; //Sender's private key $from = "hx8dc6ae3d93e60a2dddf80bfc5fb1cd16a2bf6160"; $to = "hxf8689d6c4c8f333651469fdea2ac59a18f6c242d"; $message = "Your message goes here"; // = 0.01 ICX $res = $iconservice->message($from, $to, $private_key, $message);
IRC-2:
- name
use iconation\IconSDK\IconService\IconService; use iconation\IconSDK\IconService\IRC2; $contract = 'cx8901ee4f6df58bd437de0e66c9dd3385ba4c2328'; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $irc2 = new IRC2($contract, $iconservice); $res = $irc2->name();
- symbol
use iconation\IconSDK\IconService\IconService; use iconation\IconSDK\IconService\IRC2; $contract = 'cx8901ee4f6df58bd437de0e66c9dd3385ba4c2328'; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $irc2 = new IRC2($contract, $iconservice); $res = $irc2->symbol();
- decimals
use iconation\IconSDK\IconService\IconService; use iconation\IconSDK\IconService\IRC2; $contract = 'cx8901ee4f6df58bd437de0e66c9dd3385ba4c2328'; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $irc2 = new IRC2($contract, $iconservice); $res = $irc2->decimals();
- totalSupply
use iconation\IconSDK\IconService\IconService; use iconation\IconSDK\IconService\IRC2; $contract = 'cx8901ee4f6df58bd437de0e66c9dd3385ba4c2328'; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $irc2 = new IRC2($contract, $iconservice); $res = $irc2->totalSupply();
- balanceOf
use iconation\IconSDK\IconService\IconService; use iconation\IconSDK\IconService\IRC2; $contract = 'cx8901ee4f6df58bd437de0e66c9dd3385ba4c2328'; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $irc2 = new IRC2($contract, $iconservice); $account = 'hx8dc6ae3d93e60a2dddf80bfc5fb1cd16a2bf6160'; $res = $irc2->balanceOf($account);
- transfer
use iconation\IconSDK\IconService\IconService; use iconation\IconSDK\IconService\IRC2; $contract = 'cx8901ee4f6df58bd437de0e66c9dd3385ba4c2328'; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $irc2 = new IRC2($contract, $iconservice); $from = 'hx8dc6ae3d93e60a2dddf80bfc5fb1cd16a2bf6160'; $to = 'hxf8689d6c4c8f333651469fdea2ac59a18f6c242d'; $value = '1'; $privateKey = '3468ea815d8896ef4552f10768caf2660689b965975c3ec2c1f5fe84bc3a77a5'; $res = $irc2->transfer($from, $to, $value, $privateKey);
IISS:
- setStake
use iconation\IconSDK\IconService\IconService; use iconation\IconSDK\IISS\IISS; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $iiss = new IISS($iconservice); $value = 0.5; //Stake 0.5 ICX $from = "hx8dc6ae3d93e60a2dddf80bfc5fb1cd16a2bf6160"; $private_key = "3468ea815d8896ef4552f10768caf2660689b965975c3ec2c1f5fe84bc3a77a5"; //Staker's private key $res = $iiss->setStake($value, $from, $private_key);
- getStake
use iconation\IconSDK\IconService\IconService; use iconation\IconSDK\IISS\IISS; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $iiss = new IISS($iconservice); $address = "hx8dc6ae3d93e60a2dddf80bfc5fb1cd16a2bf6160"; $res = $iiss->getStake($address);
- setDelegation
use iconation\IconSDK\IconService\IconService; use iconation\IconSDK\IISS\IISS; use iconation\IconSDK\IISS\Delegation; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $iiss = new IISS($iconservice); $delegation1 = new Delegation("hxec79e9c1c882632688f8c8f9a07832bcabe8be8f", "0x2c68af0bb140000"); $delegation1 = $delegation1->getDelegationObject(); $delegation2 = new Delegation("hxd3be921dfe193cd49ed7494a53743044e3376cd3", "0x2c68af0bb140000"); $delegation2 = $delegation2->getDelegationObject(); $delegations = array( $delegation1, $delegation2 ); $private_key = "3468ea815d8896ef4552f10768caf2660689b965975c3ec2c1f5fe84bc3a77a5"; //Staker's private key $from = "hx8dc6ae3d93e60a2dddf80bfc5fb1cd16a2bf6160"; $res = $iiss->setDelegation($delegations, $from, $private_key);
- getDelegation
use iconation\IconSDK\IconService\IconService; use iconation\IconSDK\IISS\IISS; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $iiss = new IISS($iconservice); $address = "hx8dc6ae3d93e60a2dddf80bfc5fb1cd16a2bf6160"; $res = $iiss->getDelegation($address);
- claimIScore
use iconation\IconSDK\IconService\IconService; use iconation\IconSDK\IISS\IISS; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $iiss = new IISS($iconservice); $private_key = "3468ea815d8896ef4552f10768caf2660689b965975c3ec2c1f5fe84bc3a77a5"; //Staker's private key $from = "hx8dc6ae3d93e60a2dddf80bfc5fb1cd16a2bf6160"; $res = $iiss->claimIScore($from, $private_key);
- queryIScore
use iconation\IconSDK\IconService\IconService; use iconation\IconSDK\IISS\IISS; $iconservice = new IconService('https://ctz.solidwallet.io/api/v3'); $iiss = new IISS($iconservice); $address = "hx8dc6ae3d93e60a2dddf80bfc5fb1cd16a2bf6160"; $res = $iiss->queryIScore($address);
iconation/icon-sdk-php 适用场景与选型建议
iconation/icon-sdk-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.44k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2019 年 07 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「icon」 「icx」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 iconation/icon-sdk-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 iconation/icon-sdk-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 iconation/icon-sdk-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Library to get the apple-touch-icons and favicon from a website.
Icon support for Silverstripe taxonomy terms
Craft CMS Icon Picker
Shim repository for https://github.com/olimsaidov/pixeden-stroke-7-icon
FontAwesome-FREE integration for Contao Open Source CMS
Official open source SVG icon library for Bootstrap
统计信息
- 总下载量: 20.44k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-07-20