decentfoundation / dcorephp-sdk
DCore PHP SDK library
Requires
- php: >=7.1
- ext-bcmath: *
- ext-curl: *
- ext-gmp: *
- ext-json: *
- ext-openssl: *
- bitcoin-php/bitcoin-ecdsa: 1.3.4
- codacy/coverage: ^1.4
- doctrine/annotations: 1.6.1
- kornrunner/secp256k1: ^0.1.1
- stephenhill/base58: 1.1.4
- symfony/process: ^4.2
- symfony/property-access: ^3.4
- symfony/property-info: ^4.3
- symfony/serializer: ^4.3
- symfony/validator: ^4.2
- textalk/websocket: 1.2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: 3.0.x-dev
- phpmd/phpmd: 2.6.0
- phpunit/phpunit: ^7
- squizlabs/php_codesniffer: 3.4.0
- symfony/var-dumper: ^3.4
This package is not auto-updated.
Last update: 2025-04-02 17:50:21 UTC
README
Set of APIs for accessing the DCore Blockchain.
If you are looking for other platforms you can find info below.
Requirements
- composer
- php ~7.1
- php json
- php bcmath
- php gmp
- php openssl
- symfony PropertyAccess component
- websocket-php - websocket library
- stephen-hill/base58php - base58 conversion library
- kornrunner/php-secp256k1 - secp256k1 library
- BitcoinPHP/BitcoinECDSA.php - ecdsa library
Instalation
composer.json
{ "repositories": [ { "type": "vcs", "url": "https://github.com/decentfoundation/dcorephp-sdk" } ], "require": { "decentfoundation/dcorephp-sdk": "dev-master" } }
composer require decentfoundation/dcorephp-sdk
Usage
You can find example project with SDK usage here.
You can find developer documentation for latest release here.
DCore API initialization
$dcoreApi = new \DCorePHP\DCoreApi( 'https://testnet.dcore.io/', 'wss://testnet-socket.dcore.io' );
Look at ./src/DCoreApi.php and ./src/Sdk/*Interface.php to see all available methods and their return values.
Get account
$account = $dcoreApi->getAccountApi()->get(new ChainObject('1.2.34')); $account = $dcoreApi->getAccountApi()->getByName('Your test account name');
Create account
There are two ways to create account in DCore network: $dcoreApi->getAccountApi()->registerAccount()
and $dcoreApi->getAccountApi()->createAccountWithBrainKey()
.
Recommended way to create account is using $dcoreApi->getAccountApi()->registerAccount()
method, because it has an option to specify keys. You can use $dcoreApi->getAccountApi()->createAccountWithBrainKey()
, but keys generated from $brainkey
for $publicOwnerKeyWif
, $publicActiveKeyWif
and $publicMemoKeyWif
will be the same, which is not recommended for security reasons.
$dcoreApi->getAccountApi()->registerAccount( 'Your test account name', 'DCT6MA5TQQ6UbMyMaLPmPXE2Syh5G3ZVhv5SbFedqLPqdFChSeqTz', 'DCT6MA5TQQ6UbMyMaLPmPXE2Syh5G3ZVhv5SbFedqLPqdFChSeqTz', 'DCT6MA5TQQ6UbMyMaLPmPXE2Syh5G3ZVhv5SbFedqLPqdFChSeqTz', new ChainObject('1.2.34'), '5Jd7zdvxXYNdUfnEXt5XokrE3zwJSs734yQ36a1YaqioRTGGLtn' );
Create transfer
$dcoreApi->getAccountApi()->transfer( new Credentials(new ChainObject('1.2.34'), '5Jd7zdvxXYNdUfnEXt5XokrE3zwJSs734yQ36a1YaqioRTGGLtn'), '1.2.35', (new AssetAmount())->setAmount(1500000), 'your secret message', false );
Create content
$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') );
Search content
$contents = $dcoreApi->getContentApi()->findAll( 'search term', '-rating' );
NFT
NftModels require @Type("type")
annotation for correct functioning. GMP library is also necessary when working with integers.
NftModel
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; } }
Create NFT
$credentials = new Credentials(new ChainObject('1.2.27'), ECKeyPair::fromBase58('DCT6MA5TQQ6UbMyMaLPmPXE2Syh5G3ZVhv5SbFedqLPqdFChSeqTz')); $dcoreApi->getNftApi()->create($credentials, 'APPLE', 100, false, 'an apple', NftApple::class, true);
More examples can be found in ./tests/Sdk/NftApiTest.php.
Development requirements & recommendations
- docker
- docker-compose
- phpunit
- symfony VarDumper component
- php code sniffer
- php code sniffer fixer
- php mess detector
PHPStorm configuration
- https://www.jetbrains.com/help/phpstorm/using-php-code-sniffer.html
- https://www.jetbrains.com/help/phpstorm/using-php-cs-fixer.html
- https://www.jetbrains.com/help/phpstorm/using-php-mess-detector.html
Development & testing
git clone git@github.com: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