PHP code example of decentfoundation / dcorephp-sdk

1. Go to this page and download the library: Download decentfoundation/dcorephp-sdk 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/ */

    

decentfoundation / dcorephp-sdk example snippets


$dcoreApi = new \DCorePHP\DCoreApi(
    'https://testnet.dcore.io/',
    'wss://testnet-socket.dcore.io'
);

$account = $dcoreApi->getAccountApi()->get(new ChainObject('1.2.34'));
$account = $dcoreApi->getAccountApi()->getByName('Your test account name');

$dcoreApi->getAccountApi()->registerAccount(
    'Your test account name',
    'DCT6MA5TQQ6UbMyMaLPmPXE2Syh5G3ZVhv5SbFedqLPqdFChSeqTz',
    'DCT6MA5TQQ6UbMyMaLPmPXE2Syh5G3ZVhv5SbFedqLPqdFChSeqTz',
    'DCT6MA5TQQ6UbMyMaLPmPXE2Syh5G3ZVhv5SbFedqLPqdFChSeqTz',
    new ChainObject('1.2.34'),
    '5Jd7zdvxXYNdUfnEXt5XokrE3zwJSs734yQ36a1YaqioRTGGLtn'
);

$dcoreApi->getAccountApi()->transfer(
    new Credentials(new ChainObject('1.2.34'), '5Jd7zdvxXYNdUfnEXt5XokrE3zwJSs734yQ36a1YaqioRTGGLtn'),
    '1.2.35',
    (new AssetAmount())->setAmount(1500000),
    'your secret message',
    false
);

$content = new SubmitContent();
$content
    ->setUri($randomUri)
    ->setCoauthors([])
    ->setCustodyData(null)
    ->setHash('2222222222222222222222222222222222222222')
    ->setKeyParts([])
    ->setSeeders([])
    ->setQuorum(0)
    ->setSize(10000)
    ->setSynopsis(json_encode([
        'title' => 'Your content title',
        'description' => 'Your content description',
        'content_type_id' => '1.2.3'
    ]))
    ->setExpiration('2019-05-28T13:32:34+00:00')
    ->setPrice([(new RegionalPrice)->setPrice((new AssetAmount())->setAmount(1000))->setRegion(1)]);

$credentials = new Credentials(
    new ChainObject('1.2.34'),
    ECKeyPair::fromBase58(DCoreSDKTest::PRIVATE_KEY_1)
);

$dcoreApi->getContentApi()->create(
    $content,
    $credentials,
    (new AssetAmount())->setAmount(1000)->setAssetId('1.3.0'),
    (new AssetAmount())->setAmount(1000)->setAssetId('1.3.0')
);

$contents = $dcoreApi->getContentApi()->findAll(
    'search term',
    '-rating'
);

class NftApple extends NftModel
{
    /**
     * @Type("integer")
     */
    public $size;
    /**
     * @Type("string")
     * @Unique
     */
    public $color;
    /**
     * @Type("boolean")
     * @Modifiable("both")
     */
    public $eaten;

    public function __construct($size, $color, $eaten)
    {
        $this->size = gmp_init($size);
        $this->color = $color;
        $this->eaten = $eaten;
    }
}

$credentials = new Credentials(new ChainObject('1.2.27'), ECKeyPair::fromBase58('DCT6MA5TQQ6UbMyMaLPmPXE2Syh5G3ZVhv5SbFedqLPqdFChSeqTz'));
$dcoreApi->getNftApi()->create($credentials, 'APPLE', 100, false, 'an apple', NftApple::class, true);
bash
git clone [email protected]:decentfoundation/dcorephp-sdk.git
cd dcorephp-sdk
docker-compose up -d
docker-compose exec php composer install --dev --prefer-dist --optimize-autoloader
docker-compose exec php ./vendor/bin/phpunit --bootstrap vendor/autoload.php tests