PHP code example of iconation / icon-sdk-php

1. Go to this page and download the library: Download iconation/icon-sdk-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

iconation / icon-sdk-php example snippets


use iconation\IconSDK\IconService\IconService;

$iconservice = new IconService('https://ctz.solidwallet.io/api/v3');

$res = $iconservice->getLastBlock();

use iconation\IconSDK\IconService\IconService;

$iconservice = new IconService('https://ctz.solidwallet.io/api/v3');

$res = $iconservice->getBlockByHeight('0x3');

use iconation\IconSDK\IconService\IconService;

$iconservice = new IconService('https://ctz.solidwallet.io/api/v3');

$res = $iconservice->getBlockByHash('0x123986e1c834632f6e65915c249d81cd01453ec915e3370d364d6df7be5e6c03');

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);

use iconation\IconSDK\IconService\IconService;

$iconservice = new IconService('https://ctz.solidwallet.io/api/v3');

$res = $iconservice->getBalance('hx70e8eeb5d23ab18a828ec95f769db6d953e5f0fd');

use iconation\IconSDK\IconService\IconService;

$iconservice = new IconService('https://ctz.solidwallet.io/api/v3');

$score = "cx9ab3078e72c8d9017194d17b34b1a47b661945ca";
$res = $iconservice->getBalance($score);

use iconation\IconSDK\IconService\IconService;

$iconservice = new IconService('https://ctz.solidwallet.io/api/v3');

$res = $iconservice->getTotalSupply();

use iconation\IconSDK\IconService\IconService;

$iconservice = new IconService('https://ctz.solidwallet.io/api/v3');

$txHash = '0xb89690b7598e07c286db87f05c1ee4cfc1cf915bf061007ac3404a42dc4979e9';

$res = $iconservice->getTransactionResult($txHash);

use iconation\IconSDK\IconService\IconService;

$iconservice = new IconService('https://ctz.solidwallet.io/api/v3');

$txHash = '0xb89690b7598e07c286db87f05c1ee4cfc1cf915bf061007ac3404a42dc4979e9';

$res = $iconservice->getTransactionByHash($txHash);

use iconation\IconSDK\IconService\IconService;

$iconservice = new IconService('https://ctz.solidwallet.io/api/v3');

$keys = ['lastBlock'];

$res = $iconservice->getStatus($keys);

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);

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);

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();

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();

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();

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();

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);

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);

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);

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);

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);

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);

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);

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);
shell script
apt install php-curl php-xml php-gmp php-bcmath
shell script
apt install php-mbstring
composer install
composer test